14
votes

I'm using a mac with 16gb memory, ssd hdd and still Gradle sync takes 15mins+ every time I build, clean or open the project, are there any Android Studio optimisations possible to reduce this time.

-----update----

All of these helped to some extent

  1. replace all compile 'com.package.:+' with appropriate versions, check maven repos for the latest build, better practise to develop on a version than dynamic updates, it may introduce bugs or issues.
  2. close project and restart mac/windows.
  3. Update Android studio if there is one
  4. updating gradle version
  5. turn on gradle daemon, parallel daemons and increase heap size in gradle.properties

org.gradle.daemon=true

org.gradle.parallel=true

org.gradle.jvmargs=-Xmx5120M -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError . //increase Xmx and -XX:MaxPermSize accordingly

  1. Reorder your repositories and put google's repos first. Bintray, jcenter, maven repos may have missing or corrupt google play/ google services dependencies resulting in fetch delays

example:

buildscript {
repositories {
    google()         //1st priority in search
    repo2()
    repo3()
    repo4()
    mavenCentral()
    jcenter()        //least priority, when not found in all above repos
}
3
same issue here, any luck finding a fix?Bulwinkel
All of these helped to some extent 1)replace all compile 'com.package.:+' with appropriate versions, check maven repos for the latest build, better practise to develop on a version than dynamic updates, it may introduce bugs or issues. 2)close project and restart mac/windows. 3)Update Android studio if there is one 4)changing gradel version to 2.4 didn't help me but you can try thatir2pid

3 Answers

7
votes

You're probably using a + symbol on the libraries you added to your project (and have a very slow internet connection). For example: compile 'com.android.support:support-v4:+'

This will make on every sync() gradle will check online if there's a new version. If you change to specific version number, for example: compile 'com.android.support:support-v4:22.2.0'

Then gradle will use the cached version that already been downloaded to your development machine.

1
votes

I would try to change the gradle version of your project to 2.4. If I recall correctly, studio uses 2.2 by default. I tried and I got slightly better build times on a small project. Maybe you can get better improvements.

Here you can find how: Using gradle 2.4 in Android Studio

1
votes

Just go to

File->Settings->Gradle

and tick the Offine work check box