I\'ve created an Android App which needs to be build in many (30+) flavors.
My idea was to generate the different productFlavors directly from the folde
I know there's already an answer for this, but I kind of combined Chris.Zou's approach with TheHippo. And add my own method for doing this.
Basically, when dealing with flavors, we normally work with different directories under /app/src/ which contains resources. And since the directory name is equal to the package name, I simply listed the directories under that folder (excluded "main" and "androidTest").
So here's my complete, working gradle script:
def map = [:]
new File("./app/src").eachFile() { file->
def fileName = file.getName()
if( fileName == "main" || fileName == "androidTest") {
return
}
map.put(fileName, 'com.mypackagename.' + fileName )
}
productFlavors {
map.each { flavorName, packagename ->
"$flavorName" {
applicationId packagename
}
}
}
Edit: