I have an application with many flavors (A,B,C
) and two build types (debug
,release
)
In the build type debug
I add a suffix to the application ID like so:
debug {
applicationIdSuffix '.debug'
}
This is fine for flavors A
and B
but I can't append .debug
to flavor C
's application ID.
I have looked at overriding on the variant like I have for the versionCode
but no luck.
applicationVariants.all { variant ->
def changedVersionCode = variant.versionCode
variant.
variant.outputs.each { output ->
if (variant.buildType.name != "debug") {
output.setVersionCodeOverride(project.ext.versionCode)
changedVersionCode = project.ext.versionCode
}
}
changeApkFileName(variant,changedVersionCode)
}
Is it possible to override a variants application ID depending on the flavor. For example my plan was to do something like this:
variant.buildType.name.replace('.debug','')
buildType is the how of the build. flavor is the what of the build.
You use same core ingredients to make the base but will use different toppings for each one to have a different taste. Similarly, android apps can have the same base functionalities with changes to some of the features like styles, logo etc. This can be achieved using product flavours.
You can change the build variant to whichever one you want to build and run—just go to Build > Select Build Variant and select one from the drop-down menu. To start customizing each build variant with its own features and resources, however, you'll need to know how to create and manage source sets.
Build Type refers to build and packaging settings like signing configuration for a project. For example, debug and release build types. The debug will use android debug certificate for packaging the APK file. While, release build type will use user-defined release certificate for signing and packaging the APK.
Is it possible to override a variants application ID depending on the flavor
Yes it is possible.
The reason you are not able to see the expected id is:
Because Gradle applies the build type configuration after the product flavor, the application ID for the "C" build variant will be "
<your-applicaion-id>.debug
".
So if you want it to be different for different flavors then you have to segregate the applicationIdSuffix
for different flaovors and remove it from debug {}
as follows:
android {
defaultConfig {
applicationId "<your-application-id>"
}
productFlavors {
A {
applicationIdSuffix ".debug"
}
B {
applicationIdSuffix ".debug"
}
C {
applicationIdSuffix ""
}
}
}
For more details, refer to official documentation.
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