I'm trying to migrate from Eclipse/ANT to Android Studio/Gradle. Our current ant-build supports N customers (build-targets) and a customer is defined by a triplet skin/player/customer. Every skin/player/customer may contain src, resources, assets, ...
What is the best way to model this in Gradle?
I currently create a productFlavor for every customer as follows
productFlavors {
cust1{
applicationId='com.xyz.cust1'
customer="cust1"
skin="skinX"
player="playerA"
}
cust2{
applicationId='com.xyz.cust2'
customer="cust2"
skin="skinY"
player="playerB"
}
}
but I have problems defining the corresponding sourceSets in a compact way.
I can write something like
sourceSets.cust1 {
java.srcDir('pool/playerA/src')
res.srcDir('pool/skinX/res')
res.srcDir('pool/playerA/res')
res.srcDir('pool/cust1/res')
assets.srcDir('pool/playerA/assets')
assets.srcDir('pool/skinX/assets')
jniLibs.srcDir('pool/playerA/libs')
}
for every customer but this results in N almost identical sourceSets
I would prefer to have a single, parametrized, sourceSets like
sourceSets {
java.srcDir('pool/${player}/src')
res.srcDir('pool/${skin}/res')
res.srcDir('pool/${player}/res')
res.srcDir('pool/${customer}/res')
assets.srcDir('pool/${player}/assets')
assets.srcDir('pool/${skin}/assets')
jniLibs.srcDir('pool/${player}/libs')
}
Is this possible?
One alternative could be to create a sourceSet for every player, skin and customer and create a sourceSet for the productFlavor by combining the main sourceSet with the ones of the player, skin and customer
Input appreciated!
I'd investigate flavor dimensions (formerly known as flavor groups, also known as multi-flavor variants).
Using those, you would set up three flavor dimensions, for skin, player, and customer. Each skin gets a
productFlavor
in theskin
dimension, each player gets aproductFlavor
in theplayer
dimension, and each customer gets aproductFlavor
in thecustomer
dimension.You would then have tasks like
assembleSkinxPlayeraCust1Debug
, which would build an app fromskinx
,playera
,cust1
, anddebug
sourcesets.