Gradle flavor based on a different flavor
Is it possible that the flavor is based on a different flavor?
For example build.gradle:
productFlavors {
flavor1 {
flavorBase "main"
}
flavor2 {
flavorBase "main"
}
flavor3 {
flavorBase "main"
}
flavor4 {
flavorBase "flavor3"
}
flavor5 {
flavorBase "flavor3"
}
}
+3
bmooij
source
to share
2 answers
I faced the same problem and needed something like a base flavor and two legacy flavors.
Best solution I've come across, experienced many things after a few hours:
- Create your additional scents (scent 4 and 5) as you did for 1 and 2.
- Create folders for them and create a base folder for code shares / ressources (e.g. named flavor 3, just like for your other flavors).
-
Now define additional source kits for your child fragrances
flavor4 { res.srcDirs = ['src/flavor3/res', 'src/flavor4/res'] java.srcDirs = ['src/flavor3/java', 'src/flavor4/java'] resources.srcDirs = ['src/flavor3/java', 'src/flavor4/java'] } flavor5 { res.srcDirs = ['src/flavor3/res', 'src/flavor5/res'] java.srcDirs = ['src/flavor3/java', 'src/flavor5/java'] resources.srcDirs = ['src/flavor3/java', 'src/flavor5/java'] }
This way, in flavor3 (which is not a flavor in this sense, but I keep the name as it was), you can define common code and resources. The only drawback is that it cannot be done in the same class in the base folder and in the child folders.
+3
Peter
source
to share
You can use flavor attributes to group functions. For example:
flavorDimensions "color", "function", "data"
productFlavors {
color1 {
flavorDimension "color"
// Something
}
color2 {
flavorDimension "color"
// Something else
}
functions1 {
flavorDimension "function"
// Something
}
functions2 {
flavorDimension "function"
// Something else
}
data1 {
flavorDimension "data"
// Something
}
data2 {
flavorDimension "data"
// Something else
}
}
Then you can factor your code using the following parameters: Color1Function2Data1 or Color2Function1Data1 ...
+1
MΓ©dΓ©ric
source
to share