In my build.gradle
, I'm defining 2 different flavor dimensions:
//list flavorDimensions in override priority order
flavorDimensions 'flavor', 'platform'
//assign each productFlavor a corresponding flavorDimension
productFlavors {
flavor1 {
dimension 'flavor'
applicationId "com.flavor1"
}
flavor2 {
dimension 'flavor'
applicationId "com.flavor2"
}
mobile {
dimension 'platform'
applicationIdSuffix '.mobile'
minSdkVersion 22
}
tv {
dimension 'platform'
applicationIdSuffix '.tv'
minSdkVersion 21
}
}
I would like to be able to set versionCode
and versionName
based on the combinations, so each of the following could have it's own version info:
Was able to build a solution by combining the solutions from :
https://developer.android.com/studio/build/gradle-tips#configure-dynamic-version-codes
project.ext{
flavor1Mobile_versionName = "1.0.0"
flavor1Mobile_versionCode = 3
flavor1Tv_versionName = "1.0.2"
flavor1Tv_versionCode = 5
flavor2Mobile_versionName = "3.0.0"
flavor2Mobile_versionCode = 10
flavor2Tv_versionName = "2.0.0"
flavor2Tv_versionCode = 4
}
project.android.applicationVariants.all {variant ->
def versionName = project.ext."${variant.flavorName}_versionName"
def versionCode = project.ext."${variant.flavorName}_versionCode"
variant.outputs.each { output ->
output.versionNameOverride = versionName
output.versionCodeOverride = versionCode
}
}