I'm building my Android app with the Gradle plugin. I'm using the flavors feature to create four different variants. At the moment, it's a single dimension with four values, but it would be more logical to set it up as two dimensions with two values each. I've got that building, but this is where I run into trouble.
I need each of the four variants to have a different package name. The first three are easy since I have a default and each dimension can override the package, but I need to set a package name for when both non-default dimensions are in play.
flavorDimensions "foo", "bar"
productFlavors {
boring.flavorDimension "foo"
charm {
flavorDimension "foo"
packageName "com.example.charm"
}
strange {
flavorDimension "bar"
packageName "com.example.strange"
}
// This is the idea of what I want, but it doesn't work because there
// must be only a single dimension specified here.
charmStrange {
flavorDimension "foo", "bar"
packageName "com.example.charminglystrange"
}
}
I tried setting it after declaration by looking up the composed flavor variant, but I didn't have much luck. I'm not very familiar with Gradle, so I'm sure there's trickery I haven't employed. Alternately, maybe I could specify the package name in src/charmStrange/AndroidManifest.xml
and let the merge sort it out? That seems like it could cause problems in the future.
I had a similar question this answer isn't tested in my case I was appending the product flavor to the app id set by the other dimension, using your example it would append .strange to package com.example.charm
but in your case you want a full package name so something like
charmStrange might need to be CharmStrange, try playing with it
You will want to set the applicationId, not the packageName:
You can now set applicationIdSuffix for productFlavors:
Source: http://android-developers.blogspot.ie/2015/12/leveraging-product-flavors-in-android.html