Building many product flavors is too slow
Asked Answered
S

1

15

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.

Symphonize answered 11/3, 2015 at 11:23 Comment(1)
Updated the latest experimental Gradle plugin and the poor performance remains. In my case, dynamically generating around 300 product flavors (debug + release) takes 3 to 4.5 minutes on MacBook Pro 2015 with Intel Core i5 2.7GHz and 8GB RAM.Recha
N
16

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.

Neelon answered 8/6, 2016 at 5:33 Comment(6)
I ran into same issues as OP. This worked out great for me. Thanks!Kei
aflavorname should I have to change it every time I change my flavour, or can we make it dynamic according to the flavour selected?Creight
Well... once you added aflavorname you CAN'T change the flavor... so i guess u have to change it every time you wish to change the flavor and you can't do it dynamicNeelon
I'm going to frame it and hang it on the wall. something perfect :)Yokoyama
Can multiple clients be added to dev.props? DEV FLAVOR=android1, android2, android3Yokoyama
It's absolutely incredible how bad this is. I get why it would slow down a gradle sync, but when I'm building why the hell doesn't it ignore other flavors to begin with? Anyway, thanks for this. Life saver, even 7 years later.Alchemist

© 2022 - 2024 — McMap. All rights reserved.