I have problem, when I am still adding new flavors, it takes more and more time to build. I add it like this:
productFlavors {
okapps {
applicationId = 'cz.anywhere.okapps'
signingConfig = AdamSigningVariable
versionCode = 41
versionName = "3.0.1"
android.sourceSets {
okapps.res.srcDirs = ['src/adam_okapps_resources/res', 'src/okapps/res']
}
}
...
...
}
When I comment all other flavors and only one is uncommented and build, it takes about 10 seconds. But when I build all (about 180 flavors), it takes almost 5 minutes.
When to use Product Flavors. When we want to address the issue of having separate project code for each version of the app while still having one project code. Given a scenario where you have a free and a paid app you can limit features in the free and expose all the other features in the paid version of the app.
Android Product Flavors are also known as Android build types or Android build variants are the native Android app development way to implement different versions of the same application with minor changes.
Product flavours lets you create multiple variants of an android app while using a single codebase. To create product flavours you need to define rules in the build.
Dynamic Dependencies slow down your build since they keep searching for the latest builds every time. To improve the performance we need to fix the version in place. Use only those dependencies that you need. For example google maps dependency, instead of importing compile 'com.
You can try and ignore the other product flavor you are not using, we did it as following:
Add to build.gradle
android {
productFlavors{
.
.
.
}
if (project.rootProject.file('dev.props').exists()){
def devProps = new Properties()
devProps.load(project.rootProject.file('dev.props').newDataInputStream())
def currentDevFlavor = devProps.DEV_FLAVOR
android.variantFilter { variant ->
def flavorName = variant.getFlavors().get(0).name
if(currentDevFlavor && !flavorName.equals(currentDevFlavor)) {
variant.setIgnore(true);
}
}
}
}
And then add a file dev.props
with the line DEV_FLAVOR=aflavorname
This way when u sync, gradle will act like there is only one flavor, and u dont need to comment anything.
You can also add dev.props
to .gitignore
.
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