Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle plugin 3.0 rewrite versionName

I migrated to Android studio 3 and using gradle plugin v3.0.0-beta6. I would like to rewrite versionName/vesionCode of output .apk files. I used following code for gradle plugin 2.x in the build.gradle of my Android app module

applicationVariants.all { variant ->
    def flavor = variant.mergedFlavor

    flavor.versionName="${VERSION_NAME}"
    if (variant.buildType.isDebuggable()) {
        flavor.versionCode=9999
    } else {
        flavor.versionCode=Integer.parseInt(gitCommitCount)
    }
}

It doesn't work on gradle plugin v3.0.0-beta6. For versionCode, I successfully rewrite it with the solution in this Gradle 3.0.0 alpha variant output issue

like image 320
Bao Le Avatar asked Oct 02 '17 09:10

Bao Le


1 Answers

You can use the ApkVariantOutput.setVersionCodeOverride method. Just like the following:

applicationVariants.all { variant ->
    if (variant.buildType.name == "release") {
        variant.outputs.all {
            setVersionCodeOverride(project.VERSION_CODE.toInteger())
            setVersionNameOverride(project.VERSION_NAME)
        }
    }
}
like image 72
Shuyu He Avatar answered Oct 20 '22 19:10

Shuyu He