42

it's been a while that I'm using Android Studio, and up until now I was using 1.0.1, gradle was a bit slow, around 1.5 minute for assembleDebug (my project is really big!) but today I updated my AS to 1.2 and now same process takes about 7 to 10 minutes, and sometimes even with no result!

is there any setting I have to change to make it faster ? honestly taking 10 minute for every debug run is a nightmare !

Also most of the time, my cpu usage is arround 10 percent! (it is actually idle!) cause before when gradle was working it was on 100% almost all the time

Muhammad Naderi
  • 3,090
  • 3
  • 24
  • 37

5 Answers5

33

had the same problem.

What I did was to change the global gradle settings to offline work which can be done by going to Preferences => Gradle. This did make a difference.

Another method I have seen people use, but which I have not used yet is to create a gradle.properties in the gradle folder like so:

Just create a file named gradle.properties in the following directory:

/home/<username>/.gradle/ (Linux)
/Users/<username>/.gradle/ (Mac)
C:\Users\<username>\.gradle (Windows)

Add this line to the file:

org.gradle.daemon=true

Please check out this link for more options as well as a detailed explanation on speeding up gradle.

Hope this helps!.

Community
  • 1
  • 1
Smashing
  • 1,640
  • 18
  • 16
11

I was testing my app with Google+ log in. So I added release signing to debug version. App compiling in ~ 26 seconds.

build.gradle Module: app file

signingConfigs {
    debug {
        storeFile file(project.property("MyApp.signing"))
        storePassword project.property("MyApp.signing.password")
        keyAlias project.property("MyApp.signing.alias")
        keyPassword project.property("MyApp.signing.password")
    }
}

When I remove that ~ 7.5 seconds.

Next I tested offline grade

File - Settings - Build, Execution... - Build Tools - Gradle - Offline work

enter image description here

Now my app compiling in ~ 4.5 seconds.

Of course I also added turn on - Compile independent modules in parallel (may require larger heap size) - Make project automatically (only works while not running / debugging)

File - Settings - Build, Execution... - Compiler

enter image description here

Eliasz Kubala
  • 3,836
  • 1
  • 23
  • 28
1

Complete answer for this issue is as below:

  • Upgrade android studio to version 1.3(stable) or above 1.4(beta at the time of writing this).
  • Upgrade gradle to 1.3.+(+ can be replaced with some positive number) change it in your build.gradle file.
  • change your gradle-wrapper.properties files and add distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip in last(you can remove any old entry).
  • Go to Preference -> Gradle and set it to work offline.

woila!!! I am able to compile and run the code in less then ~5 sec (I really mean it)

Ankit
  • 1,916
  • 2
  • 20
  • 33
0

The reason could be multiDex,

turn multiDexEnabled to false in your build.gradle file (for debug only, keep it for release).

android {
...
    defaultConfig {
        ...
        multiDexEnabled false
        ...
    }
}

In addition you should consider to use the lastest version (2.4 at the moment) by editing the gradle-wrapper.properties file and set gradle-2.4-all.zip

distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip

What is MultiDex : https://developer.android.com/tools/building/multidex.html

sonique
  • 4,539
  • 2
  • 30
  • 39
-5

From settings go to HTTP connection and disable any proxy and you will find speed you want

xakiib
  • 1