简体   繁体   English

运行 gradlew assembleRelease 时出现 memory 错误 - react-native

[英]Out of memory error while running gradlew assembleRelease - react-native

I am getting this error while making a release build for my react native project:在为我的 react native 项目进行发布构建时出现此错误:

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 android:largeHeap="true"添加到 AndroidManifest.xml 中的应用程序标签

  2. Added添加

    dexOptions { javaMaxHeapSize "4g" }

    in the android/app/build.gradle file.在 android/app/build.gradle 文件中。

  3. Added the below code to gradle.properties将以下代码添加到 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??摆脱这个错误的任何永久方法以及它是如何引起的?

configuring gradle.properties:配置 gradle.properties:

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

Although the given answer did not work for me, it did lead me to the correct path.尽管给出的答案对我不起作用,但它确实引导我走向了正确的道路。 Sometimes the build would go through but then again after some time this error would resurface, so to resolve it once and for all:有时构建会通过,但一段时间后又会再次出现此错误,因此要一劳永逸地解决它:

First comment org.gradle.jvmargs=-Xmx4096m inside your project's gradle properties.首先在项目的 gradle 属性中注释org.gradle.jvmargs=-Xmx4096m

Add the following in your app/build.gradle:在您的 app/build.gradle 中添加以下内容:

android {

  dexOptions {
    javaMaxHeapSize "4g"
  }

}

Now edit your global gradle.properties for mac it'll be inside Home/YOUR_USERNAME/.gradle/ Note that .gradle is a hidden folder.现在编辑你的全局 gradle.properties for mac,它会在 Home/YOUR_USERNAME/.gradle/ 请注意 .gradle 是一个隐藏文件夹。

If the file is not there simply create it and add如果文件不存在,只需创建它并添加

org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

this worked for me!这对我有用!

uncommenting this line in android/gradle.properties在 android/gradle.properties 中取消注释这一行

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

credit @Alex Aymkin信用@Alex Aymkin

Adding this code in the android/gradle.properties worked for me!在 android/gradle.properties 中添加此代码对我有用!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM