Expiring Daemon because JVM heap space is exhausted

Rishabh Sagar picture Rishabh Sagar · May 10, 2019 · Viewed 51.9k times · Source

I just updated the Android Studio to 3.5 Beta 1 and I'm getting

Expiring Daemon because JVM heap space is exhausted

message while the build is running. Also, the build is taking more time to complete. Does anyone have any idea regarding this?

Answer

Jordan Grant picture Jordan Grant · Aug 19, 2019

I was able to solve this for my React Native project by configuring the following:

// gradle.properties
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

and

// app/build.gradle
android {
    dexOptions {
       javaMaxHeapSize "3g"
    }
}