Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 808
Dishant Chanchad Avatar asked Nov 26 '19 05:11

Dishant Chanchad


People also ask

How do I fix Java heap space error?

OutOfMemoryError: Java heap space. 1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.

What happens when Java runs out of heap space?

OutOfMemoryError is a runtime error in Java which occurs when the Java Virtual Machine (JVM) is unable to allocate an object due to insufficient space in the Java heap. The Java Garbage Collector (GC) cannot free up the space required for a new object, which causes a java. lang.

How do I fix invalid max heap size?

64 bit JVM installed on Solaris machines runs with a 32-bit model if you don't specify either -d32 or -d64, which won't accept a Maximum heap size of 4GB, hence "invalid heap size". You can resolve this issue by running Solaris JVM with option -d64.


3 Answers

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"
  }

}
like image 102
Ahmed AlAskalany Avatar answered Nov 09 '22 05:11

Ahmed AlAskalany


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
like image 33
REACT NATIVE Avatar answered Nov 09 '22 05:11

REACT NATIVE


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
like image 33
Moumit Avatar answered Nov 09 '22 05:11

Moumit