Android Studio Gradle Build takes more than 5 minutes

Other solutions here have not helped me yet. I am seeing builds lasting 30+ minutes only to end with Error:Out of memory: GC overhead limit exceeded. But I have made slight progress the past few days.

Note: I do not believe this is a solution to the problem, just a workaround until Jack works out the kinks

I added the following to my build gradle:

android {
    ....
  defaultConfig {
    ....
    jackOptions {
            enabled true
            additionalParameters('jack.incremental': 'true')
        }
    }

    compileOptions {
        incremental true
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dexOptions {
        javaMaxHeapSize '4096m'
    }

}

For some reason, adding

org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 

to my gradle.properties made no difference. I had to add it in the dexOptions.


Enable "Dex In Process" for faster app builds (for Android Studio 2.1).

increase the amount of memory allocated to the Gradle Daemon VM by 1 Gb, to a minimum of 2 Gb, using the org.gradle.jvmargs property:

org.gradle.jvmargs=-Xmx2048m

Read about it here: Faster Android Studio Builds with Dex In Process

dexinprocess