java.lang.OutOfMemoryError: GC overhead limit exceeded解决

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

具体值的大小要根据具体机器的内存而定,内存太少设置的值大一样会出现问题。

你可能感兴趣的:(java.lang.OutOfMemoryError: GC overhead limit exceeded解决)