Learn to Fix React Native JVM Heap Space Is Exhausted

React Native Android Build Errors — Quick Read

jQN
2 min readAug 27, 2020
Photo by Sarah Kilian on Unsplash

If you keep seeing this error multiple times 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 it means you need to increase your JVM Heap memory. This error only was happening when trying to build an APK for React Native Android.

$ ./gradlew assembleRelease

And this is the dreaded output:

./gradlew assembleRelease

I found two solutions from my Google search

The first solution is to increase the Heap Size in android/app/build.gradle

android/app/build.gradle

That didn’t help but you might want to try it first just because it might work for you.

The second solution is to increase the Heap Size in android/gradle.properties This solution finally worked and I was able to generate the .apk I needed.

android/gradle.properties
...
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx4096m

If you continue running into memory build errors I have another short post that goes over MultiDex errors during the build.

Note: if you are using Firebase modules in your app, they place a heavy demand on the Android build system so they might also be causing the out of memory errors. This option might also resolve them.

Uncomment the alternate Gradle memory setting in /android/gradle.properties

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

Please clap and share this post if it helped you out. Thanks for reading.

--

--

jQN

I'm a Full-Stack Software Engineer who believes in the power of technology to change and improve lives. Connect with me on https://twitter.com/FullStackJQN