Out of Memory Error While Building React Native for Android

You might run into a java.lang.OutOfMemoryError error while trying to build React Native for Android emulators and Android devices.

You can explore some of the solutions discussed in this known React Native issue.

You can also try adding org.gradle.jvmargs=-Xmx4608m to the gradle.properties file in the android folder of your React Native project.

Your gradle.properties file might look like this:

org.gradle.jvmargs=-Xmx1536M
org.gradle.configureondemand=false
android.useAndroidX=true
android.enableJetifier=true