I was able to solve this for my React Native project by configuring the following:
1. gradle.properties
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
2. app/build.gradle
android {
dexOptions {
javaMaxHeapSize "3g"
}
}