The versionCode for the android apk gets set in defaultConfig. I would like to change for each of my build types but it seems like this can only be done by flavours? Is there another way to override the versionCode, maybe similar to the way the outputFileName is updated?
how to manipulate apk variant versioncode
1.3k views Asked by user1584120 At
3
There are 3 answers
0
On
In your project root build.gradle you could define version code and version Name some thing like this
def code = project.hasProperty('versionCode') ? versionCode.toInteger() :
(System.getenv("VERSION_CODE") as Integer ?: <default-version-code>)
def name = project.hasProperty('versionName') ? versionName.toString() :
(System.getenv("VERSION_NAME") as String ?: "<default-version-name>")
You could provide version code and name runtime in the build command something like this -P = value
allprojects {
ext.baseVersionCode = code
ext.baseVersionName = name
}
These version code your could access in you all modules.In the app build.gradle
defaultConfig {
versionCode baseVersionCode
versionName baseVersionName
archivesBaseName = "customzied_apk_name"
}
I think your case fit perfectly with product flavors.
You set a flavor for prod and a flavor for stage. In both set version code as your expression (e.g. 300 + android.defaultConfig.versionCode for prod, and 200 + android.defaultConfig.versionCode for release)
Then, when you want to run or deploy a version you choose between the 4 combinations in Build Variants that will be: prodRelease, prodDebug, stageRelease and stageDebug