How to fix “OutOfMemoryError: java heap space” whi

2019-01-18 04:52发布

问题:

When I try to compile (not execute) one of my projects, I recently get the following error:

Tool /usr/bin/java execution started with arguments: -jar /Applications/android-sdk-mac_x86/platform-tools/lib/dx.jar --no-strict --dex --output=obj/Debug/android/bin/classes.dex obj/Debug/android/bin/classes /Developer/MonoAndroid/usr/lib/mandroid/platforms/android-8/mono.android.jar FlurryAnalytics/Jars/FlurryAgent.jar Jars/android-support-v4.jar 

    UNEXPECTED TOP-LEVEL ERROR:
    java.lang.OutOfMemoryError: Java heap space
        at com.android.dx.rop.code.RegisterSpecSet.<init>(RegisterSpecSet.java:49)
        at com.android.dx.rop.code.RegisterSpecSet.mutableCopy(RegisterSpecSet.java:383)
        at com.android.dx.ssa.LocalVariableInfo.mutableCopyOfStarts(LocalVariableInfo.java:169)
        at com.android.dx.ssa.LocalVariableExtractor.processBlock(LocalVariableExtractor.java:104)
        at com.android.dx.ssa.LocalVariableExtractor.doit(LocalVariableExtractor.java:90)
        at com.android.dx.ssa.LocalVariableExtractor.extract(LocalVariableExtractor.java:56)
        at com.android.dx.ssa.SsaConverter.convertToSsaMethod(SsaConverter.java:50)
        at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:99)
        at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:73)
        at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:273)
        at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:134)
        at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:87)
        at com.android.dx.command.dexer.Main.processClass(Main.java:487)
        at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
        at com.android.dx.command.dexer.Main.access$400(Main.java:67)
        at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
        at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
        at com.android.dx.command.dexer.Main.processOne(Main.java:422)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
        at com.android.dx.command.dexer.Main.run(Main.java:209)
        at com.android.dx.command.dexer.Main.main(Main.java:174)
        at com.android.dx.command.Main.main(Main.java:91)

Other projects build as expected. I think I need to increase the heap size for this java build step? But how?

回答1:

There is an option in Xamarin Studio to increase the Java Heap Size.

Project Options -> Android Build -> Advanced -> Java Heap Size.



回答2:

This suggestion did the trick:

$ export _JAVA_OPTIONS="-Xmx1g"
$ /Applications/MonoDevelop.app/Contents/MacOS/MonoDevelop

I have a few jar files in my project. Flurry, Maps and Newtonsoft... aparently this is enough to bomb the build.

Thanks to the awesome Xamarin Support team for their quick response and pointing out the solution! They are working on reducing the needed memory footprint for external jars.