Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reduce Gradle sync time in Android studio

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
}
like image 753
ir2pid Avatar asked Jun 14 '15 11:06

ir2pid


People also ask

Why does Gradle project sync take so long?

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 long will it take for Gradle to sync?

One bit of a downside is that it takes roughly 3 minutes to re-sync when we "Import Gradle Project".


3 Answers

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.

like image 180
Budius Avatar answered Nov 05 '22 14:11

Budius


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

like image 31
flower_green Avatar answered Nov 05 '22 13:11

flower_green


Just go to

File->Settings->Gradle

and tick the Offine work check box

like image 1
Hojjat Avatar answered Nov 05 '22 15:11

Hojjat