Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - change app version name based on flavor

I want to change the app versionName to whatever is defined in the AndroidManifest file for the specific flavor I'm building.

So if I'm only building one of the 4 defined flavors I have, like:
gradle assembleFlavor1Debug

I was expecting Flavor1 to have the same version name as the one defined for its specific manifest (because of the merging of manifest files), but that's not happening.

How can I know, during build time, which specific flavor is being built?
Because if I know what flavor is being run,
I can extract the respective versionName from the manifest and set it on android.defaultConfig.versionName,
which solves my problem.

like image 397
Tsimmi Avatar asked Oct 02 '22 05:10

Tsimmi


1 Answers

As of at least Android Studio 3.1.1 you can do this...

defaultConfig {
    versionName "1.0.0"
}
flavorDimensions "dimen1", "dimen2"
productFlavors {
    'flavor1' {
        dimension "dimen1"
        versionNameSuffix "-F1"
    }

    ...

    'flavorA' {
        dimension "dimen2"
        versionNameSuffix "-FA"
    }
}

Then for variant flavor1FlavorA the versionName would be 1.0.0-F1-FA

https://developer.android.com/studio/build/build-variants#product-flavors

like image 127
Tom Bollwitt Avatar answered Oct 13 '22 11:10

Tom Bollwitt