获取错误:java.lang.OutOfMemoryError:超出了GC开销限制

时间:2016-06-17 10:23:09

标签: java android garbage-collection heap

我收到错误:意外的顶级。日志显示增加堆大小。我在应用程序中添加了android:largeHeap = true。然后我也收到了这个错误。

清单:

  <application
    android:allowBackup="true"
    android:name="android.support.multidex.MultiDexApplication"
    android:icon="@drawable/icon1"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

日志:

To run dex in process, the Gradle daemon needs a larger heap.
It currently has approximately 910 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB.
To do this set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties.
For more information see https://docs.gradle.org/current/userguide/build_environment.html
Error:UNEXPECTED TOP-LEVEL ERROR:
Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
Error:  at java.util.Arrays.copyOf(Arrays.java:3236)
Error:  at java.io.ByteArrayOutputStream.toByteArray(ByteArrayOutputStream.java:191)
Error:  at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:279)
Error:  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
Error:  at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
Error:  at com.android.dx.command.dexer.Main.processOne(Main.java:672)
Error:  at com.android.dx.command.dexer.Main.processAllFiles(Main.java:569)
Error:  at com.android.dx.command.dexer.Main.runMultiDex(Main.java:366)
Error:  at com.android.dx.command.dexer.Main.run(Main.java:275)
Error:  at com.android.dx.command.dexer.Main.main(Main.java:245)
Error:  at com.android.dx.command.Main.main(Main.java:106)
:app:transformClassesWithDexForDebug FAILED
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 3
Information:BUILD FAILED
Information:Total time: 7 mins 31.106 secs
Information:14 errors
Information:0 warnings
Information:See complete output in console

怎么办?

3 个答案:

答案 0 :(得分:2)

build.gradle尝试添加此内容:

dexOptions {
    incremental true
    javaMaxHeapSize "4g"
}
  • incremental true用于加速您的构建。
  • javaMaxHeapSize "4g"指定dex进程的堆大小。

答案 1 :(得分:2)

日志说

  

“要在项目中设置org.gradle.jvmargs = -Xmx2048M   gradle.properties“。

所以打开你的gradle.properties文件并添加“org.gradle.jvmargs = -Xmx2048M”行

答案 2 :(得分:0)

您的日志:

  

要在项目中设置org.gradle.jvmargs = -Xmx2048M   gradle.properties