Expiring Daemon because JVM heap space is exhausted

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

}

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