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
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)
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With