I have a project with 4 flavor dimensions, which is making it hard to share resources between some combinations of flavors.
FlavorA {dimension 'Dimension1'}
FlavorB {dimension 'Dimension1'}
FlavorC {dimension 'Dimension2'}
FlavorD {dimension 'Dimension2'}
FlavorE {dimension 'Dimension3'}
FlavorF {dimension 'Dimension3'}
FlavorG {dimension 'Dimension4'}
FlavorH {dimension 'Dimension4'}
In my project, I need every FlavorAFlavorC build variant to share some resource.
However, the only available source sets are in the following form:
- FlavorA
- FlavorB
- ...
- FlavorH
- FlavorAFlavorCFlavorEFlavorG
- FlavorAFlavorCFlavorEFlavorH
- FlavorAFlavorCFlavorFFlavorG
- ...
I tried having some custom folders, like a FlavorAFlavorC folder, and then in applicationVariants.all:
if(variant.name.contains('FlavorA') && variant.name.contains('FlavorC')){
variant.mergeResourcesProvider.get().doFirst {
android.sourceSets.debug.res.srcDirs += "src/FlavorAFlavorC/res"
android.sourceSets.release.res.srcDirs += "src/FlavorAFlavorC/release/res"
}
}
This solution, however, is extremely inconsistent. Upon further investigation I came to the conclusion that this inconsistency derives from setting android.nonTransitiveRClass=true on gradle.properties.
Is there a better way to share resources between certain subsets of flavors or to avoid the issue caused by the flag?