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"
}
}
There is no "current flavor". The Gradle build file is building an object model of the build process. It is not an interpreted script only being used once a build is underway and a "current flavor" is known.
To define a flavor specific dependency you can use proCompile instead of compile in your dependency section. When you run gradle properties you get an overview of automatic created configurations.
123 let's go Simply put, a product flavor is a variant of your app. It is very useful when you want to create multiple versions of your app. This means you can generate different versions or variants of your app using a single codebase.
A build type determines how an app is packaged. By default, the Android plug-in for Gradle supports two different types of builds: debug and release . Both can be configured inside the buildTypes block inside of the module build file.
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.
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