2

I have a gradle build that has 32 flavors and builds for 5 hours?

Here is my build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 17
    buildToolsVersion "21.1.2"

    dexOptions {
        preDexLibraries false
    }

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 17
        multiDexEnabled true
        versionCode 3
        versionName '3.0.0.0'
    }

    signingConfigs {
        signingConfig1 {
            storeFile file('keystores/signingConfig1.keystore')
            storePassword 'signingConfig1'
            keyAlias 'signingConfig1'
            keyPassword 'signingConfig1'
        }

        ...
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }

    productFlavors {
        flavor1 {
            applicationId "com.mycompany.project.flavor1"
            signingConfig signingConfigs.signingConfig1
        }

        flavor2 {
            applicationId "com.mycompany.project.flavor2"
            signingConfig signingConfigs.signingConfig2
        }

        ...

        flavor32 {
            applicationId "com.mycompany.project.flavor32"
            signingConfig signingConfigs.signingConfig32
        }
    }

    sourceSets {
        flavor1.res.srcDir 'src-flavors/flavor1/res'
        flavor2.res.srcDir 'src-flavors/flavor2/res'
        ...
        flavor32.res.srcDir 'src-flavors/flavor32/res'
    }
}

dependencies {
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:support-v4:18.0.0'
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile files('libs/stock-chart-full.jar')
    compile files('libs/bcprov-jdk15on-1.47.jar')
    compile files('libs/Pubnub-Android-3.7.2.jar')
    compile 'com.google.android.gms:play-services:7.0.0'
    compile 'org.roboguice:roboguice:3.+'
    provided 'org.roboguice:roboblender:3.+'
    compile 'com.google.code.findbugs:jsr305:1.3.9'
}

My gradle.properties

org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true

What can I do to speed up the build of the application? If I build only one flavor for debug|release the build took 3 minutes, if I build all in debug and release it is taking more than 3 hours. Most of the time gradle is spending of the DEX tasks.

  • Are you sure this is the correct build structure for your app? 32 flavors is quite a lot... Maybe your solution shouldn't be increase build speed, but reduce number of flavors. Build time is 32 flavors * 2 build types (debug / release) * 3 minutes = approximately 3 hours like you said. – Aster Apr 28 '15 at 12:23
  • Did you consider building a computer farm of 32 computers ? – Thomas Apr 28 '15 at 12:25

3 Answers3

3

If you're using Android Studio the easiest solution is to go to Preferences -> Gradle and enable Offline Work

LambergaR
  • 2,433
  • 4
  • 24
  • 34
1

This has been around for some time now.

Unfortunately, android studio's make seems to perform a clean every single time, causing the previously DEX'd files to be deleted.

AFAIK you cannot do more than what you already did. It is something Google should work on (regarding the DEX phase).

See related: Building and running app via Gradle and Android Studio is slower than via Eclipse

shkschneider
  • 17,833
  • 13
  • 59
  • 112
1

EDIT: Jack and Jill are deprecated and are no longer supported!

Maybe you could try the new experimental android toolchain Jack and Jill: http://tools.android.com/tech-docs/jackandjill

Christopher
  • 9,682
  • 7
  • 47
  • 76
  • 1
    This appears to be a dead project? Updates stops at gradle 1.0.0, while 1.3 is available. – 3c71 Sep 19 '15 at 19:23