I have my android application split into four different build flavours. Each of these flavours have a portion of unique java
and xml
files, and a portion of shared files under main
. For the sake of clarity, let's call these Cucumber
, Tomato
, Onion
and Pepper
. These flavours have unique layouts, drawables, strings, colours, java files, etc.
My requirement is now that I need to split my Pepper
flavour into two sub-flavours; Red-Pepper
and Green-Pepper
. The layouts for these two flavours should be identical - the only different is that the two flavours must use different drawable
and string
resources. I don't want to have duplicate layout files in both the red and green flavours for obvious reasons.
How can this be achieved in gradle
?
You can define multiple resource folders.
In this way you can use common folders for 2 flavors (in you redPepper and greenPepper).
For example something like this:
android {
...
sourceSets {
main {
//....
res.srcDirs = ['/src/main/res']
}
redPepper {
res.srcDirs = ['/src/flavorRed/res', '/src/commonPepper/res']
}
greenPepper {
res.srcDirs = ['/src/flavorGreen/res', '/src/commonPepper/res']
}
//.....other flavors
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With