Android Studio Google JAR file causing GC overhead

2019-01-02 15:12发布

I am using Android Studio on OS X. I am getting this error message:

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:preDexDebug'. com.android.ide.common.internal.LoggedErrorException: Failed to run command: /Applications/Android Studio.app/sdk/build-tools/android-4.4W/dx --dex --output /Users/alex/AndroidStudioProjects/SilentSMS/app/build/intermediates/pre-dexed/debug/android-4.3_r2.1-f22bbff4d1017230e169a4844a9c2195f13060d2.jar /Users/alex/AndroidStudioProjects/SilentSMS/app/libs/android-4.3_r2.1.jar

    Error Code: 3 Output:

  UNEXPECTED TOP-LEVEL ERROR:
  java.lang.OutOfMemoryError: GC overhead limit exceeded
      at com.android.dx.cf.code.RopperMachine.getSources(RopperMachine.java:665)
      at com.android.dx.cf.code.RopperMachine.run(RopperMachine.java:288)
      at com.android.dx.cf.code.Simulator$SimVisitor.visitLocal(Simulator.java:612)
      at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:412)
      at com.android.dx.cf.code.Simulator.simulate(Simulator.java:94)
      at com.android.dx.cf.code.Ropper.processBlock(Ropper.java:782)
      at com.android.dx.cf.code.Ropper.doit(Ropper.java:737)
      at com.android.dx.cf.code.Ropper.convert(Ropper.java:346)
      at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:282)
      at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:139)
      at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:94)
      at com.android.dx.command.dexer.Main.processClass(Main.java:682)
      at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
      at com.android.dx.command.dexer.Main.access$600(Main.java:78)
      at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
      at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
      at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
      at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
      at com.android.dx.command.dexer.Main.processOne(Main.java:596)
      at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
      at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
      at com.android.dx.command.dexer.Main.run(Main.java:230)
      at com.android.dx.command.dexer.Main.main(Main.java:199)
      at com.android.dx.command.Main.main(Main.java:103)

I am using this library:

http://grepcode.com/snapshot/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/

I pulled the JAR file and added it to my project - the project I am trying to build is:

https://github.com/domi007/silentSMS/

I understand it is because my xms and xmx values are too low. I increased them in:

/Applications/Android Studio.app/bin/idea.vmoptions so that it now says:

-Xms256m
-Xmx1024m

However, I still get the error. What could this be caused by? Apart from the silentSMS app being an Eclipse project and me porting the code over to Android Studio I haven't changed anything. In terms of Android Studio spotting errors - it doesn't, and everything else looks fine.

7条回答
春风洒进眼中
2楼-- · 2019-01-02 15:16

I think there's a separate way to raise the heap limit of the dexing operation. Add this to your android closure in your build.gradle file:

dexOptions {
    javaMaxHeapSize "4g"
}

and see if that helps.

(idea courtesy of this answer from Scott Barta)

查看更多
若你有天会懂
3楼-- · 2019-01-02 15:17

This new issue is caused by the latest version of Android.

Go to your project root folder, open gradle.properties, and add the following options:

org.gradle.daemon=true

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

org.gradle.parallel=true

org.gradle.configureondemand=true

Then add these changes in your build.gradle file:

dexOptions {
        incremental = true
        preDexLibraries = false
        javaMaxHeapSize "4g" // 2g should be also OK
}
查看更多
君临天下
4楼-- · 2019-01-02 15:21

In my case, to increase the heap-size looks like this:

Using Android Studio 1.1.0

android {
    dexOptions {
        incremental true
        javaMaxHeapSize "2048M"
    }
}

Put the above code in your Build.gradle file.

查看更多
浪荡孟婆
5楼-- · 2019-01-02 15:23

Add this to build.gradle file

dexOptions {
   javaMaxHeapSize "2g"
}
查看更多
伤终究还是伤i
6楼-- · 2019-01-02 15:27

I forced closed all Java.exe from taskmanger, restarted Android Studio and it worked for me

enter image description here

查看更多
浮光初槿花落
7楼-- · 2019-01-02 15:37

For me non of the answers worked I saw here worked. I guessed that having the CPU work extremely hard makes the computer hot. After I closed programs that consume large amounts of CPU (like chrome) and cooling down my laptop the problem disappeared.

For reference: I had the CPU on 96%-97% and Memory usage over 2,000,000K by a java.exe process (which was actually gradle related process).

查看更多
登录 后发表回答