Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android gradle project builds very slowly

We have changed our Android app project to use gradle, but have noticed it is building significantly slower.

Before with ANT:
6 sek / 50 sec (with clean)

After with gradle:
30 sek / 80 sec (with clean)

I have profiled the solution with:

gradle assembleDebug --profile

The main tasks in the resulting report was thies tasks: (in the build without clean)

:packageDebug   10.690s     
:processDebugResources  8.795s  
:compileDebugJava   7.644s  

I don't have any ideas about getting more details information about thies tasks.

Is this normal? How could this be improved?
I know the new build system is still in betas, but it seems like others are building much faster.


I have looked around without finding a solution I have tried several things including making sure gradle deamon is enabled with a gradle.properties file containing this:

org.gradle.daemon=true
org.gradle.jvmargs=-Xms128m -Xmx256m
org.gradle.parallel=true

build.gradle:

buildscript {
    repositories {
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
        classpath 'com.google.guava:guava:14.0.1'
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
        classpath 'me.tatarka:gradle-retrolambda:1.1.1'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2'
    }
}

repositories {
    mavenCentral()
    maven { url 'http://download.crashlytics.com/maven' }
}

apply plugin: 'android'
apply plugin: 'crashlytics'
apply plugin: 'retrolambda'
apply plugin: 'android-apt'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.google.guava:guava:14.0.1'
    compile 'com.crashlytics.android:crashlytics:1.+'
    apt "org.androidannotations:androidannotations:3.0.1"
    compile "org.androidannotations:androidannotations-api:3.0.1"
}

apt {
    arguments {
        resourcePackageName "com.example"
        androidManifestFile variant.processResources.manifestFile
    }
}

android {
    packagingOptions { //Fix: http://stackoverflow.com/a/20675331/860488
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    compileSdkVersion 10
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 10
        buildConfigField "boolean", "useProductionServices", "true"
    }

    buildTypes {
        testflight.initWith(buildTypes.debug)
        debug {
            packageNameSuffix ".debug"
            buildConfigField "boolean", "useProductionServices", "false"
        }

        testflight {
            packageNameSuffix ".testflight"
            buildConfigField "boolean", "useProductionServices", "true"
        }

        release {
            buildConfigField "boolean", "useProductionServices", "true"
        }
    }
}

retrolambda {
    compile "net.orfjackal.retrolambda:retrolambda:1.1.2"
    jdk System.getenv("JAVA8_HOME")
}
like image 620
Morten Holmgaard Avatar asked Feb 27 '14 14:02

Morten Holmgaard


People also ask

Why are Gradle builds so slow?

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.

Why does Gradle project take so long to sync?

Check your Internet connection. If internet speed is very slow gradle build will also take long time to build. I check by change my wifi internet connection with another one good speed connection. Now build time is normal.

How much time Gradle build takes?

When I joined my current company a few months ago, building our Android app took an average of 14 minutes on my machine.


1 Answers

I have same issue and solved by this setting :

File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle -> Offline work

after this setting reduce time by 3 minute to 2s728ms

enter image description here

like image 125
Dhaval Jivani Avatar answered Oct 22 '22 15:10

Dhaval Jivani