How to Fix React Native JVM out of Memory Once & For All
./gradlew assembleRelease
If the above command is giving you sleepless nights let me help you out.
The dreaded error:
Daemon will be stopped at the end of the build after running out of JVM memory followed by Expiring Daemon because JVM heap space is exhausted when trying to build an APK for React Native on Android.
I tried several solutions given on StackOverflow, GitHub, etc. But none of them worked perfectly.
So to resolve this once & for all, follow these steps:
- Comment or remove
org.gradle.jvmargs=-Xmx4096m
from inside your project's Gradle properties. (You might have given a different memory allocation instead of 4096m) - Add the following in your app/build.gradle:
android {
dexOptions {
javaMaxHeapSize "4g"
}
}
3. Now edit your global gradle.properties for Mac it’ll be inside Home/YOUR_USERNAME/.gradle/
Note - .gradle is a hidden folder. Press Command + Shift + . (period) to make the hidden files appear.
If the file is not there simply create it and add
org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
You won’t ever see the JVM out of memory error again and your build will successfully go through 🚀