Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is gradle 2.0 so slow?

I'm using Gradle 2.0.0 with Android Studio and an empty project takes 2 minutes to build. It also creates a 100% CPU usage under Windows 8.1.

Very annoying. Even more annoying that a proper project can take up to 4-5 minutes to build, and it slows everything down.

What could cause this?

like image 347
breakline Avatar asked Sep 10 '25 20:09

breakline


1 Answers

Have the same problem since 2.0.0-rc3. And sometimes after long build (about 10 minutes) getting gc overhead limit exceeded error.

UPD: Also it uses about 6 GB disk space on SSD.

Have the next configuration:

in app's build.gradle:

dexOptions {
        javaMaxHeapSize "4g"
    }

in gradle-wrapper.properties:

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

UPD 2: I think I've found temporary solution - I've turned off Instant Run and added next configs:

in the gradle.properties:

org.gradle.jvmargs=-Xms512m -Xmx2048m
org.gradle.daemon=true
org.gradle.parallel=true

in the build.gradle:

dexOptions {
        incremental true
        javaMaxHeapSize "4g"
    }

in the studio.vmoptions:

-server
-Xms1G
-Xmx2G
-XX:MaxPermSize=450m
-XX:MetaspaceSize=512m

You can find studio.vmoptions in:

Mac OS:

~/Library/Preferences/{FOLDER_NAME}/

Linux:

~/.{FOLDER_NAME}/studio.vmoptions and/or ~/.{FOLDER_NAME}/studio64.vmoptions

Windows:

%USERPROFILE%\.{FOLDER_NAME}\studio.exe.vmoptions and/or %USERPROFILE%\.{FOLDER_NAME}\studio64.exe.vmoptions

UPD 3: I think, I've found why Android Studio uses so much disk space.

After every gc overhead limit exceeded error Android Studio creates a file java_pid<proccess_id_number_here>.hprof in your project's root folder.

It has size about 1.2 Gb, a lot of the gc overhead limit exceeded errors -> a lot of those files. You can just delete them.

UPD 4: Builds became much faster, after updating to Android Studio version 2.1 and adding property maxProcessCount in the dexOptions

dexOptions {
        incremental true
        maxProcessCount 4
        javaMaxHeapSize "5g"
    }

Also, I've increased the maximum heap size for the Gradle in the gradle.properties:

org.gradle.jvmargs=-Xmx5120M
org.gradle.daemon=true
org.gradle.parallel=true

And I'm still using modified studio.vmoptions file, as I've described above.

like image 69
c0nst Avatar answered Sep 13 '25 19:09

c0nst