Java Android Studio Google JAR 文件导致 GC 开销限制超出错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25013638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Studio Google JAR file causing GC overhead limit exceeded error
提问by amlwwalker
I am using Android Studio on OS X. I am getting this error message:
我在 OS X 上使用 Android Studio。我收到此错误消息:
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:
FAILURE:构建失败,出现异常。
出了什么问题:任务 ':app:preDexDebug' 执行失败。com.android.ide.common.internal.LoggedErrorException:无法运行命令:/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-2.1.
错误代码:3 输出:
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.access0(Main.java:78)
at com.android.dx.command.dexer.Main.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/
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:
我提取了 JAR 文件并将其添加到我的项目中 - 我正在尝试构建的项目是:
https://github.com/domi007/silentSMS/
https://github.com/domi007/silentSMS/
I understand it is because my xms and xmx values are too low. I increased them in:
我明白这是因为我的 xms 和 xmx 值太低了。我增加了它们:
/Applications/Android Studio.app/bin/idea.vmoptions so that it now says:
/Applications/Android Studio.app/bin/idea.vmoptions 现在显示:
-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.
但是,我仍然收到错误消息。这可能是由什么引起的?除了silentSMS 应用程序是一个Eclipse 项目并且我将代码移植到Android Studio 之外,我没有进行任何更改。在 Android Studio 发现错误方面 - 它没有,其他一切看起来都很好。
采纳答案by CommonsWare
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:
我认为有一种单独的方法可以提高 dexing 操作的堆限制。将此添加到您android
的build.gradle
文件中的闭包中:
dexOptions {
javaMaxHeapSize "4g"
}
and see if that helps.
看看这是否有帮助。
(idea courtesy of this answer from Scott Barta)
(这个想法来自 Scott Barta 的回答)
回答by Dhruv Raval
In my case, to increase the heap-sizelooks like this:
就我而言,增加堆大小如下所示:
Using Android Studio 1.1.0
使用 Android Studio 1.1.0
android {
dexOptions {
incremental true
javaMaxHeapSize "2048M"
}
}
Put the above code in your Build.gradlefile.
将上面的代码放在你的Build.gradle文件中。
回答by u5542367
I disable my Instant Run by:
我通过以下方式禁用我的 Instant Run:
Menu Preference→ Build→ Instant Run "Enable Instant Run to hot swap code"
菜单首选项→构建→即时运行“启用即时运行热插拔代码”
I guess it is the Instant Run that makes the build slow and creates a large size pidXXX.hprof file which causes the AndroidStudio gc overhead limit exceeded.
我猜是 Instant Run 使构建变慢并创建了一个大尺寸的 pidXXX.hprof 文件,导致超出了 AndroidStudio gc 开销限制。
(My device SDK is 19.)
(我的设备 SDK 是 19。)
回答by Selvaganesan Saminathan
This new issue is caused by the latest version of Android.
这个新问题是由最新版本的 Android 引起的。
Go to your project root folder, open gradle.properties
, and add the following options:
转到您的项目根文件夹,打开gradle.properties
并添加以下选项:
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:
然后在您的build.gradle
文件中添加这些更改:
dexOptions {
incremental = true
preDexLibraries = false
javaMaxHeapSize "4g" // 2g should be also OK
}
回答by Hitesh Sahu
回答by olNoy
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.
对我来说,我在这里看到的所有答案都不起作用。我猜想 CPU 非常努力地工作会使计算机变热。在我关闭消耗大量 CPU(如 Chrome)的程序并冷却我的笔记本电脑后,问题就消失了。
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).
供参考:我通过 java.exe 进程(实际上是与 gradle 相关的进程)使 CPU 处于 96%-97% 并且内存使用量超过 2,000,000K。
回答by Ghulam Rasool
Add this to build.gradle file
将此添加到 build.gradle 文件
dexOptions {
javaMaxHeapSize "2g"
}
回答by pableiros
I'm using Android Studio 3.4
and the only thing that worked for mewas to remove the following lines from my build.gradle
file:
我正在使用Android Studio 3.4
,唯一对我有用的是从我的build.gradle
文件中删除以下几行:
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
Because Android Studio 3.4
is using R8
in full mode
and is not direct compatible with Proguard
因为Android Studio 3.4
是用R8
在里面full mode
并且不直接兼容Proguard
回答by sana ebadi
in my case, I Edit my gradle.properties
:
在我的情况下,我编辑我的 gradle.properties
:
note: if u enable the minifyEnabled true
:
注意:如果您启用 minifyEnabled true
:
remove this line :
删除这一行:
android.enableR8=true
and add this lines in ur build.gradle
, android
block :
并在 ur build.gradle
, android
block 中添加以下行:
dexOptions {
incremental = true
preDexLibraries = false
javaMaxHeapSize "4g" // 2g should be also OK
}
hope this help some one :)
希望这对某人有所帮助:)
回答by Pabel
4g is a bit overkill, if you do not want to change buildGradle you can use FILE -> Invalid caches / restart.
4g 有点矫枉过正,如果您不想更改 buildGradle,您可以使用 FILE -> Invalid caches / restart。
Thats work fine for me ...
那对我来说很好用......