To run dex in process, the Gradle daemon needs a larger heap. It currently has approximately 910 MB

Update from June 25, 2017

At Google IO 2017 there was some updates about this topic. It’s not recommended anymore to set the flag on the dexOptions, so if you have something like the next, you can delete it.

dexOptions {
   javaMaxHeapSize "2g"
}

Original answer:

Android Studio 2.1 enables Dex In Process which shares the VM with Gradle to improve build times. Due to this, it’s necessary to increase the size of the Gradle daemon to incorporate those Dex processes.

At least it’s necessary 2 gigs of memory, but you can try with three if you can afford it.

gradle.properties.

org.gradle.jvmargs=-Xmx3072m

By default the Java max heap size is one gig, but in case you have modified it on the build.gradle file…

build.gradle (App)

dexOptions {
   javaMaxHeapSize "2g"
}

…you have to resize the Gradle daemon size accordingly (has to be bigger to fit the heap).

Notes:

  • Please realize above numbers varies from machine to machine.

Leave a Comment