I am getting this error while making a release build for my react native project:
Expiring Daemon because JVM heap space is exhausted > Task :app:transformDexArchiveWithDexMergerForRelease FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:transformDexArchiveWithDexMergerForRelease'. > java.lang.OutOfMemoryError (no error message)
Done some research and made some changes, which are below:
Added android:largeHeap="true"
to the application tag in the AndroidManifest.xml
Added
dexOptions { javaMaxHeapSize "4g" }
in the android/app/build.gradle file.
Added the below code to gradle.properties
org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError org.gradle.daemon=true org.gradle.parallel=true org.gradle.configureondemand=true
Still I am not able to get rid of this error. Any permanent way to get rid of this error and how is it caused??
This can be fixed by increasing the configured max heap size for the project. Through GUI: In the Settings, search for 'Memory Settings' and increase the IDE max heap size and Daemon max heap size as per the system RAM availability.
To fix Java Heap Space error in react native project, just add the heap size you wish to the app/build. gradle file. Here I've specified the Heap size to be 4gb. This solution could also fix JVM Heap Space is exhausted error.
If you haven't yet encountered an OOM in your Android application, you will in the near future. Memory leaks cause the OutOfMemoryError in Android. To eliminate the OutOfMemoryError, you must first eliminate memory leaks from your Android application. The 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.
configuring gradle.properties:
org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError org.gradle.daemon=true org.gradle.parallel=true org.gradle.configureondemand=true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With