I have a Android Gradle project that has multiple flavors like so.
android {
...
productFlavors {
apple {
applicationId "com.myapp.apple"
}
orange {
applicationId "com.myapp.orange"
}
banana {
applicationId "com.myapp.banana"
}
}
...
}
In my build.gradle
I also have the following piece of code that sets the versionName
to either 0.8-dev if it's an local build or 0.8-123 if it's a Jenkin's build.
android {
...
defaultConfig {
...
// Get the build number from Jenkins, otherwise use 'dev'
ext.buildNumber = System.getenv("BUILD_NUMBER") ?: "dev"
versionName "0.8-$buildNumber"
...
}
}
Since I now have different flavors of the same project, I'd like to prefix the versionName
with the flavor so it looks something like this apple-0.8-dev or orange-0.8-dev, depending on which flavor is built.
How do I go about doing this?
I've tried using BuildConfig.FLAVOR
but I can't access that in build.gradle
.
Re-define the versionName
in your flavors:
def version="0.8"
android {
defaultConfig {
versionName version
}
...
productFlavors {
apple {
applicationId "com.myapp.apple"
versionName "apple-$version"
}
orange {
applicationId "com.myapp.orange"
versionName "orange-$version"
}
banana {
applicationId "com.myapp.banana"
versionName "banana-$version"
}
}
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With