ubuntu 12.04 server(64位) 编译android遇到java虚拟机堆内存不够的问题
UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError: GC overhead limit exceeded
at com.android.dx.dex.code.OutputFinisher.findExpandedOpcodeForInsn(OutputFinisher.java:525)
at com.android.dx.dex.code.OutputFinisher.calculateReservedCount(OutputFinisher.java:466)
at com.android.dx.dex.code.OutputFinisher.reserveRegisters(OutputFinisher.java:402)
at com.android.dx.dex.code.OutputFinisher.finishProcessingAndGetList(OutputFinisher.java:358)
at com.android.dx.dex.code.DalvCode.finishProcessingIfNecessary(DalvCode.java:108)
at com.android.dx.dex.code.DalvCode.getInsns(DalvCode.java:185)
at com.android.dx.dex.file.CodeItem.place0(CodeItem.java:223)
at com.android.dx.dex.file.OffsettedItem.place(OffsettedItem.java:242)
at com.android.dx.dex.file.MixedItemSection.placeItems(MixedItemSection.java:312)
at com.android.dx.dex.file.DexFile.toDex0(DexFile.java:543)
at com.android.dx.dex.file.DexFile.toDex(DexFile.java:216)
at com.android.dx.command.dexer.Main.writeDex(Main.java:574)
at com.android.dx.command.dexer.Main.run(Main.java:218)
at com.android.dx.command.dexer.Main.main(Main.java:174)
at com.android.dx.command.Main.main(Main.java:95)
make: *** [out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/noproguard.classes-with-local.dex] error 3
解决方法:
方法一:
用java命令指定java虚拟机堆的大小来把需要编译的东西先编译出来,可能需要几分钟。
java -Xms3550M -Xmx3550M -jar /home/test/4.0/out/host/linux-x86/framework/dx.jar --dex --output=out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/noproguard.classes-with-local.dex --core-library out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/noproguard.classes.jar
运行完这个后。再重新make就好了,因为这个包已经被make出来了,所以重新make的时候不会再去编译它这个方法只能是make出错后在执行上述命令,然后在接着执行make命令
方法二:
修改definitions.mk文件 此文件位于build/core/目录下
修改变量 :transform-classes.jar-to-dex中的-JXms16M -JXmx1024M值
代码中的变量定义:
define transform-classes.jar-to-dex
@echo "target Dex: $(PRIVATE_MODULE)"
@mkdir -p $(dir $@)
$(hide) $(DX) \
$(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx1024M) \
--dex --output=$@ \
$(if $(NO_OPTIMIZE_DX), \
--no-optimize) \
$(if $(GENERATE_DEX_DEBUG), \
--debug --verbose \
--dump-to=$(@:.dex=.lst) \
--dump-width=1000) \
$(PRIVATE_DX_FLAGS) \
$<
endef
将-JXms16M -JXmx1024M 修改成适当的值
我的机器是内存是32G的,我将-JXms16M -JXmx1024M修改为-JXms1024M -JXmx2048M
具体值的大小要根据具体机器的内存而定,内存太少设置的值大一样会出现问题。
编译android4.1.1遇到的问题:
问题1:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Vector.<init>(Vector.java:111) at java.util.Vector.<init>(Vector.java:124) at org.antlr.analysis.DFA.createTransitionTableEntryForState(DFA.java:551) at org.antlr.analysis.DFA.createStateTables(DFA.java:440) at org.antlr.codegen.CodeGenerator.genLookaheadDecision(CodeGenerator.java:645) at org.antlr.grammar.v3.CodeGenTreeWalker.block(CodeGenTreeWalker.java:2876) at org.antlr.grammar.v3.CodeGenTreeWalker.rule(CodeGenTreeWalker.java:2382) at org.antlr.grammar.v3.CodeGenTreeWalker.rules(CodeGenTreeWalker.java:1537) at org.antlr.grammar.v3.CodeGenTreeWalker.grammarSpec(CodeGenTreeWalker.java:1441) at org.antlr.grammar.v3.CodeGenTreeWalker.grammar_(CodeGenTreeWalker.java:461) at org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:421) at org.antlr.Tool.generateRecognizer(Tool.java:655) at org.antlr.Tool.process(Tool.java:468) at org.antlr.Tool.main(Tool.java:93) make: *** [out/host/common/obj/JAVA_LIBRARIES/smali_intermediates/smaliLexer.java] Error 1 make: *** Waiting for unfinished jobs....
这个问题同样是提示java虚拟机内存的问题,解决的思路是一样的,但解决这个问题需要修改的是external/smali/smali/Android.mk
这个mk文件,将Android.mk文件中的$(GEN): PRIVATE_CUSTOM_TOOL = java -jar $(ANTLR_JAR) -fo $(dir $@) $<.这行,修改为
$(GEN): PRIVATE_CUSTOM_TOOL = java -Xmx512m -jar $(ANTLR_JAR) -fo $(dir $@) $<.
问题2:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.zip.ZipOutputStream.getUTF8Bytes(ZipOutputStream.java:498)
at java.util.zip.ZipOutputStream.writeLOC(ZipOutputStream.java:348)
at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:179)
at java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:92)
at com.android.tools.layoutlib.create.AsmGenerator.createJar(AsmGenerator.java:241)
at com.android.tools.layoutlib.create.AsmGenerator.generate(AsmGenerator.java:225)
at com.android.tools.layoutlib.create.Main.main(Main.java:98)
make: *** [out/host/common/obj/JAVA_LIBRARIES/temp_layoutlib_intermediates/javalib.jar] 错误 1
make: *** 正在删除文件“out/host/common/obj/JAVA_LIBRARIES/temp_layoutlib_intermediates/javalib.jar”
这个问题也是java虚拟机内存的问题,解决的方法是修改frameworks/base/tool/layoutlib/Android.mk
将文件中的 $(hide) java -jar $(built_layoutlib_create_jar) \ 这行修改为如下:
$(hide) java -Xmx512M -jar $(built_layoutlib_create_jar) \