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.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
Tsimmi
  • 1,828
  • 6
  • 23
  • 35
  • Previous answer to this question: http://stackoverflow.com/questions/19726119/android-change-flavor-version-name-based-on-build-type – Turnsole Mar 27 '14 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. – Tsimmi Mar 27 '14 at 16:36
  • i had same issue. check this [answer](https://stackoverflow.com/a/19737482/4908528) – S.Hossein Emadi Oct 30 '19 at 12:31

2 Answers2

4

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

Tom Bollwitt
  • 10,849
  • 1
  • 17
  • 11
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
}
}
A J
  • 4,542
  • 5
  • 50
  • 80