I have many Android flavors for a project that I would like to extract to a separate directory. A solution I came up with looks like this:
my-folder/flavors.gradle:
ext.flavorConfig = {
productFlavors {
flavorA {
dimension "Adim"
...
}
...
}
}
Module’s build.gradle:
apply from: "${rootProject.projectDir}/my-folder/flavors.gradle"
...
android {
flavorDimensions "Adim", "Bdim"
productFlavors {
flavorB {
dimension "Bdim"
}
...
}
with flavorConfig
productFlavors.all { flavor ->
if (flavor.name.contains('Adim') ) {
sourceSets.configureEach({ sourceSet ->
if (sourceSet.name.contains(flavor.name)) {
print(sourceSet.name + "\t" + flavor.name + "\n")
sourceSet.resources.srcDirs += "${rootProject.projectDir}/my-folder/src/${flavor.name}/res"
sourceSet.assets.srcDirs += "../my-folder/src/${flavor.name}/assets"
}
})
}
}
The project syncs with Gradle with no problems, but I cannot build it. I suspect that the resources are missing.
- Is there an easier way to achieve what I’m trying to?
- What am I doing wrong?