5

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.

3
  • Previous answer to this question: stackoverflow.com/questions/19726119/… Commented Mar 27, 2014 at 16:30
  • @Turnsole the question you mentioned is very clear:'change flavor version name based on build type'. I don't want to change the versionName based on the 'build type', but rather on the specific flavor I'm building. Commented Mar 27, 2014 at 16:36
  • i had same issue. check this answer Commented Oct 30, 2019 at 12:31

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

Comments

1

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
}
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.