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

查看:20
本文介绍了即时运行 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!

编辑 1:

还有什么有趣的,如果我重新启动我的 android studio,第一次运行成功,但第二次没有.

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

编辑 2:

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

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

编辑 3:

问题似乎出在即时运行上,如果我强制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天全站免登陆