javaout-of-memoryreact-native

Error occurred when executing gradlew assembleRelease - react-native


I am getting this error while making a release build for my react native project:

Expiring Daemon because JVM heap space is exhausted
    
> Task :app:transformDexArchiveWithDexMergerForRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithDexMergerForRelease'.
> java.lang.OutOfMemoryError (no error message)

Done some research and made some changes, which are below:

  1. Added android:largeHeap="true" to the application tag in the AndroidManifest.xml

  2. Added

    dexOptions {
        javaMaxHeapSize "4g" 
    }
    

    in the android/app/build.gradle file.

  3. Added the below code to gradle.properties

    org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError
    org.gradle.daemon=true
    org.gradle.parallel=true
    org.gradle.configureondemand=true
    

Still I am not able to get rid of this error. Any permanent way to get rid of this error and how is it caused??


Solution

  • configuring gradle.properties:

    org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError
    org.gradle.daemon=true
    org.gradle.parallel=true
    org.gradle.configureondemand=true