Dishant Chanchad
Dishant Chanchad

Reputation: 787

Expiring Daemon because JVM heap space is exhausted?

I just updated the Android Studio to 3.5.0 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 error help me?

Upvotes: 18

Views: 26931

Answers (5)

Bharat Lalwani
Bharat Lalwani

Reputation: 1520

Just add this line in gradle-wrapper-properties

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

here -Xmx4g will provide dex size to 4Gb, same as javaMaxHeapSize. XX:MaxPermSize is the permanent heap size to allocate.

Upvotes: 0

REACT NATIVE
REACT NATIVE

Reputation: 193

As you add more modules to your app, there is an incredible demand placed on the Android build system, and the default memory settings will not work. To avoid OutOfMemoryErrors during Android builds, you should uncomment the alternate gradle memory setting present in /android/gradle.properties:

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

Upvotes: 14

Khurshid Ansari
Khurshid Ansari

Reputation: 5075

Solution: 1) Add following in android/app/build.gradle:

android: {
...
   dexOptions {
      javaMaxHeapSize: "4g"
   }
}

Add following in android/gradle.properties:

org.gradle.daemon=true
org.gradle.jvmargs=-Xmx4096m

Upvotes: 0

Moumit
Moumit

Reputation: 9530

After trying couple of solution below code finally resolve the error

Add below in gradle.properties

org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xmx1028m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

Upvotes: 1

Ahmed AlAskalany
Ahmed AlAskalany

Reputation: 1610

I had the same problem, and the following answer helped but needs to be adapted to React Native.

https://stackoverflow.com/a/57548822/6798074

Make your gradle.properties look like the following:

android.useAndroidX=true
android.enableJetifier=true
org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

And add the following in your app/build.gradle under the android task:

android {

  dexOptions {
    javaMaxHeapSize "4g"
  }

}

Upvotes: 53

Related Questions