Reputation: 18120
I have an issue that is directly related to this question: How to have two build flavors inherit from a root flavor in Android Studio? but it makes sense to pull it out into another question. I have this in my build.gradle:
flavorGroups 'fruit', 'paid'
productFlavors {
apple {
flavorGroup 'fruit'
}
orange {
flavorGroup 'fruit'
}
free {
flavorGroup 'paid'
}
premium {
flavorGroup 'paid'
}
}
I have four unique applications at this point.
But they do not have unique package names/application ids just yet.
How do I set up four unique app ids/package names in this situation?
What I've tried?
In the previous question @Scott Barta suggested just to set the package names in the manifest for each of the four application.
When I tried creating four additional manifests (Note: I had my single "core" manifest before in /main) I got an error: Manifest merger failed : Main AndroidManifest.xml at AndroidManifest.xml manifest:package attribute is not declared. It seems as though I removed the package name from the core manifest file (in /main) it doesn't want to build.
Upvotes: 3
Views: 3898
Reputation: 6075
The simplest way to customize the applicationId
is to use Gradle's applicationIdSuffix
property. Example below:
defaultConfig {
applicationId 'com.example'
}
flavorGroups 'fruit', 'paid'
productFlavors {
apple {
flavorGroup 'fruit'
applicationIdSuffix '.apple'
}
orange {
flavorGroup 'fruit'
applicationIdSuffix '.orange'
}
free {
flavorGroup 'paid'
applicationIdSuffix '.free'
}
premium {
flavorGroup 'paid'
applicationIdSuffix '.premium'
}
}
Gradle has a full-featured programming language, Groovy, built in, so you can do more elaborate voodoo than this, but this is the easiest way.
Upvotes: 2