Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

android - instant run java.lang.OutOfMemoryError: GC overhead limit exceeded

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

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

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:'
}

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: method ID not in [0, 0xffff]: 65536

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!

EDIT 1:

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

EDIT 2:

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

EDIT 3:

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Found Here

And on my build.gradle :

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

....

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...