Reputation: 142
Is it possible that a flavor is based on a other flavor?
For example build.gradle:
productFlavors {
flavor1 {
flavorBase "main"
}
flavor2 {
flavorBase "main"
}
flavor3 {
flavorBase "main"
}
flavor4 {
flavorBase "flavor3"
}
flavor5 {
flavorBase "flavor3"
}
}
Upvotes: 5
Views: 441
Reputation: 186
I ran into the same issue and needed something like a base flavor and two inherited flavors from that.
The best solution I ended up with after a few hours of trying out a lot of things was:
Now define additional source sets for your child flavors
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']
}
So in flavor3 (which is in that sense not a flavor but I keep the naming as it was) you can define common code and resources. The only downside is, that its not possible do have the same class in the base folder and in the child folders.
Upvotes: 4
Reputation: 948
You could use flavor dimensions to group features. 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 factorize your code using these dimension like that : Color1Function2Data1 or Color2Function1Data1...
Upvotes: 1