即时运行java.lang.OutOfMemoryError:超出了GC开销限制 [英] instant run java.lang.OutOfMemoryError: GC overhead limit exceeded

查看:681
本文介绍了即时运行java.lang.OutOfMemoryError:超出了GC开销限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已升级到Android Studio 2.1,并且在尝试构建&时出现此错误.运行我的公司大项目:

I have upgraded to Android Studio 2.1 and I got this error while I am trying to build & run my corporate big project:

任务':app:transformClassesWithDexForMyAppDebug'的执行失败. com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException:java.lang.OutOfMemoryError: 超出了GC开销限制

Execution failed for task ':app:transformClassesWithDexForMyAppDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded

我已经搜索了整个论坛并禁用了即时运行,还写了我的build.gradle:

I have searched through the forum and disabled instant run, also write to my build.gradle:

dexOptions {
    incremental true
    javaMaxHeapSize "6g"
}
...
dependencies{
    compile 'com.android.support:multidex:'
}

但是它不能解决我的问题. 我在gradle中启用了multidex,因为没有它我会收到错误:

But it doasn't solved my problem. I have multidex enabled in my gradle, because I get the error without it:

com.android.dex.DexIndexOverflowException:方法ID不在[0,0xffff]中:65536

com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

因此这是解决方案,它以前可以与早期版本的Android Studio配合使用(也适用于公司中其他使用Android Studio 1.4-2.0的版本),但不适用于我,因为我升级了Android工作室.

so this was the solution for it, and it worked before with the previous versions of Android Studio (also working for the others in the company, who are using Android Studio 1.4-2.0) but not for me since I upgraded my Android Studio.

有人知道导致问题的原因吗?

Do anyone have an idea what can cause the problem?

有趣的是,如果我只是创建项目,则只有在尝试运行该错误时,我才不会收到该错误.任何想法表示赞赏!

What is also interesting that if I just make the project I don't get the error, only if I try to Run it. Any idea is appreciated!

还有意思的是,如果我重新启动android studio,则第一次运行会成功,但是第二次则不会成功.

What is also interesting, that if I restart my android studio, than the first run is successful, but the second is not.

如果我将堆大小设置为大于应用程序的大小(例如8-10g),甚至在第一次运行时就无法编译.

If I set the heap size to bigger (like 8-10g) than the app not even compiles at first run.

问题似乎与即时运行有关,如果我强迫android studio不使用它(例如一次部署到两个设备或更改gradle.properties这样的答案),该错误就会消失.

It seems that the problem is with instant run, if I force android studio to not use it (like deploying to two devices at once or changeing gradle.properties like in the answer) the error disappears.

推荐答案

将此添加到您的gradle.properties文件中.

Add this to your gradle.properties file.

# The Gradle daemon aims to improve the startup and execution time of Gradle.
# When set to true the Gradle daemon is to run the build.
org.gradle.daemon=true

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true

# Enables new incubating mode that makes Gradle selective when configuring projects.
# Only relevant projects are configured which results in faster builds for large multi-projects.
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:configuration_on_demand
org.gradle.configureondemand=true

找到此处

在我的build.gradle上:

....
     dexOptions
         {
               incremental false
               javaMaxHeapSize "2048M" 
               preDexLibraries = false
         }//end dexOptions

....

这篇关于即时运行java.lang.OutOfMemoryError:超出了GC开销限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆