Question

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.

Was it helpful?

Solution

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

OTHER TIPS

You can do this in this way

productFlavors
{
test
{
 applicationId 'com.example.test'
 versionName '1.0.0.test'
 versionCode 1
}

product
{
 applicationId 'com.example.product'
 versionName '1.0.0.product'
 versionCode 1
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top