Extremely long build with Gradle (Android Studio)

Solution 1:

I'm not quite sure why Android Studio is slower than the command line, but you can speed up your builds by turning on incremental dexing. In your module's build file, add this option to your android block:

dexOptions {
    incremental true
}

In that dexOptions block you can also specify the heap size for the dex process, for example:

dexOptions {
    incremental true
    javaMaxHeapSize "4g"
}

These options are taken from a thread on the adt-dev mailing list (https://groups.google.com/forum/#!topic/adt-dev/r4p-sBLl7DQ) which has a little more context.

Solution 2:

Our team was facing the same issue. Our project exceeds the method limit for dex(>65k). So, in out library project we put below options in build.gradle:

dexOptions {
    jumboMode = true
    preDexLibraries = false
}

In our project build.gradle:

 dexOptions {
    jumboMode = true
//  incremental true
}

previously we had incremental true. after commenting it its taking around 20s to run as compared to 2mins 30 seconds. I don't know this may solve your problem. but it can help to others. :)