I have Gradle Android project that will be used for several customers. Also it will have free and paid version. I realized that it can be achieved by using flavorDimensions. But the problem is that I want to have a method to generate package name depending on selected flavors.
flavorDimensions 'branding', 'version'
productFlavors {
free {
flavorDimension 'version'
}
paid{
flavorDimension 'version'
}
customer1 {
flavorDimension 'branding'
}
customer2 {
flavorDimension 'branding'
}
}
// pseudocode
def getGeneratePackageName() {
if (customer1 && free) {
return 'com.customer1.free'
}
if (customer2 && free) {
return 'com.customer2.free'
}
if (customer1 && paid) {
return 'com.customer1.paid'
}
if (customer2 && paid) {
return 'com.customer2.paid'
}
}
I wonder when do I need to call this method and what variable do I need to set?
Figured it out how to implement this. Groovy code below allows to get flexibility in generation of package names.