標籤:使用者 vm虛擬機器 使用者目錄 路徑 指定 expec build 最大 表示
背景:
問題:
Q1:UNEXPECTED TOP-LEVEL ERROR:java.lang.OutOfMemoryError: Java heap spaceat com.android.dx.cf.direct.MethodListParser.set(MethodListParser.java:80)at com.android.dx.cf.direct.MemberListParser.parse(MemberListParser.java:217)at com.android.dx.cf.direct.MemberListParser.parseIfNecessary(MemberListParser.java:108)at com.android.dx.cf.direct.MethodListParser.getList(MethodListParser.java:54)at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:542)at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)at com.android.dx.command.dexer.Main.parseClass(Main.java:764)at com.android.dx.command.dexer.Main.access$1500(Main.java:85)at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1684)at com.android.dx.command.dexer.Main.processClass(Main.java:749)at com.android.dx.command.dexer.Main.processFileBytes(Main.java:718)at com.android.dx.command.dexer.Main.access$1200(Main.java:85)at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1645)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:672)at com.android.dx.command.dexer.Main.processAllFiles(Main.java:569)at com.android.dx.command.dexer.Main.runMultiDex(Main.java:366)at com.android.dx.command.dexer.Main.run(Main.java:275)at com.android.dx.command.dexer.Main.main(Main.java:245)at com.android.dx.command.Main.main(Main.java:106):transformClassesWithDexForDebug FAILED:transformClassesWithDexForDebug (Thread[main,5,main]) completed. Took 5 mins 2.571 secs.FAILURE: Build failed with an exception.* What went wrong:Execution failed for task ‘:transformClassesWithDexForDebug‘.> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘/g3an/ci/jdk1.7.0_79/bin/java‘‘ finished with non-zero exit value 3* Try:Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
原因:gradle在編譯過程中棧記憶體溢出
解決方案:在build.gradle設定檔中增加
dexOptions { javaMaxHeapSize "2g" }
//2g表示記憶體大小,32位的jdk最大好像不能超過3g,超過最大允許記憶體大小時會報下面這個錯誤
Successfully started process ‘command ‘/g3an/ci/jdk1.7.0_79/bin/java‘‘Invalid maximum heap size: -Xmx4gThe specified size exceeds the maximum representable size.Error: Could not create the Java Virtual Machine.Error: A fatal exception has occurred. Program will exit.
Q2:
UNEXPECTED TOP-LEVEL ERROR:java.lang.OutOfMemoryError: GC overhead limit exceeded:transformClassesWithDexForDebug FAILED:transformClassesWithDexForDebug (Thread[main,5,main]) completed. Took 1 mins 58.823 secs.FAILURE: Build failed with an exception.* What went wrong:Execution failed for task ‘:transformClassesWithDexForDebug‘.> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘/g3an/ci/jdk1.7.0_79/bin/java‘‘ finished with non-zero exit value 3* Try:Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
原因:JVM虛擬機器的記憶體空間太小
解決方案:在使用者目錄下的gradle.properties檔案中指定gradle編譯時間使用的jvm空間大小
檔案路徑:/home/[user]/.gradle/wrapper/gradle.properties
在檔案中增加:org.gradle.jvmargs=-Xmx2048m
android gradle打包常見問題及解決方案