Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Java heap space OutOfMemoryError when binding a big .jar

Hi, I'm trying to bind BurstlySDK to my mono for Android project.

According to the steps described here

I did the following:

created Android Java Bindings library project called "BurstlyBindingLibrary"

created Jars filter there and a corresponding folder, copied BurstlySDK.jar, added to project, set EmbeddedJar in properties.

added 2 other jars on which Burstly was dependant (admobfix.jar and joda-time-2.1.jar) and marked them as EmbeddedReferenceJar in properties.

tweaked the Metadata.xml to remove and rename some nodes in API.xml so that BurstlyBindingLibrary finally compiles.

to the main project added the same 3 jars and marked them as AndroidJavaLibrary in properties

right-clicked on the main project, Add reference, selected project BurstlyBindingLibrary ("BurstlyBindingLibary" now shows in References of the main project)

Now, when trying to build the main project, I get the following error:

  java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(
at java.lang.AbstractStringBuilder.expandCapacity(
at java.lang.AbstractStringBuilder.append(
at java.lang.StringBuilder.append(

Googling only finds this: which says the jar has >65k methods. Is this the case here, too(?)

BurstlySDK.jar is pretty big (2.8MB) and contains lots of stuff inside, probably indeed >65k methods.

I tried making a usual android project in Eclipse and added the BurstlySDK.jar there, it builds fine and runs on the device, though it seems to strip the jar (BurstlySDK....jar inside bin/dexedLibs/ is only 1MB instead of 2.8MB) since the test project in Eclipse does nothing except BurstlySDK.init(..).

If the huge amount of methods is the problem, then I guess the solution would be to remove more nodes from API.xml, maybe entire packages. Or is this something else.

Any suggestions? Thanks!



  • JenniferRostenneJenniferRostenne USMember ✭✭

    Ok, so even after I remove all nodes with

    <remove-node path="/api" />

    and don't access any code from the jar in the main project, the same error still happens.
    Btw the resulting BurstlyBindingLibrary.dll file is still 3MB, I wonder why since there are absolutely no .cs files in obj/Debug/generated/

  • JenniferRostenneJenniferRostenne USMember ✭✭

    Another solution could be to increase Java heap space with

    java -Xmx2g 

    but where can one edit this for Mono?

  • JenniferRostenneJenniferRostenne USMember ✭✭

    In some places including here I've seen that the OutOfMemory error can be solved if one uses 64-bit version of Java.

    I installed both 1.7 and 1.6 64bit versions of JDK but can't find where to tell Mono which JDK to use.

    Here they say to edit the file find_java.bat in the SDK's installation.

    Seems like Mono plugin for Visual Studio installs (on Windows 7 64 bit) it's own copy of Android SDK into


    the file find_java.bat should contain %PROGRAMFILES% or %PROGRAMFILES(X86)% which could be changed to take the 64 bit version of Java. But apparently Mono has them tweaked and they just call find_java.exe.

    I don't remember exactly but there seem to be a mentioning in the official Android SDK docus that it won't compile on Java 64 bit.

    Seems like I've run out of ideas how this error could be solved.

  • JenniferRostenneJenniferRostenne USMember ✭✭

    Just another comment: I've tried binding a very small jar file (with just 1 class TestMath which contains 1 tiny method sum(a,b) ) instead of BurstlySDK.jar and as expected both the binding library project and the main project compile OK. So the reason of the error is apparently that with my current machine setup Mono can't handle a big .jar file.

    Sadly, I have no influence of the .jar file: I get it from a different department and in fact don't even know which parts of it can be stipped out and which not, so ideally everything should stay included and as jew nodes removed from API.xml as possible.

    I'd appreciate any help.

  • JenniferRostenneJenniferRostenne USMember ✭✭
    edited March 2013

    Apparently find_java.bat was changed by Google, there is no %PROGRAMFILES% in it also when it is inside the ADT bundle from the official Android developer page.

    I have a JAVA_HOME environment variable set to C:\Program Files\Java\jdk1.7.0_17 which is the 64bit java but this seems to have no influence on anything.

  • GlennWilsonGlennWilson USUniversity ✭✭

    I don't know if this will fix your issue, but to change the heap size you can use

    Not well documented and not standard, I guess, but it seems to work.

    The JVM picks up the contents of both JAVA_TOOL_OPTIONS and _JAVA_OPTIONS

    You can see (and change) the JDK Xamarin uses, in Mono or XS from: Tools>Options>Projects:SDK Locations.
    I don't think Java 7 is supposed to work.

  • JenniferRostenneJenniferRostenne USMember ✭✭

    Sorry, I didn't notice that, too. Thx

  • AnuragShuklaAnuragShukla USMember

    Nice. What's the default value? Getting a heap memory exception on a 64 bit OSX with plenty of memory is just wrong.

  • ArthurDentArthurDent USMember ✭✭
    edited May 2013

    Is there maximum value that JavaMaximunHeapSize>1G</JavaMaximunHeapSize can be set to?

    My project compiles ok with JavaMaximunHeapSize>1G</JavaMaximunHeapSize,

    but if I put it up to JavaMaximunHeapSize>2G</JavaMaximunHeapSize

    I get: "error MSB6006: 'java' exited with code 1."

    when I compile

    C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1018,3): error MSB6006: "java" exited with code 1.

  • JonathanPryorJonathanPryor USXamarin Team Xamurai

    Is there maximum value

    I don't know, but it certainly looks like it.

  • Matt_SeqMatt_Seq USMember

    Has the spelling mistake been fixed now? It seems to have been. If so can you reply to this thread :-)

  • Hello @jonp, I have the same problem. I have been changed all you write, but the problem persist. Only I have a listview with 20 row and the row have 1 icon and 1 edittext.

  • dear Jonp
    It worked for saved my time.thank you...

  • LarsNordlundLarsNordlund SEMember

    Changing the Heapsize in the .csproj file did it for me aswell, thanks alot!

  • Thanks guys! Personally, I had to do it three times in my .csproj file, once at the top, and once each in the Debug and Release configuration sections further down. After that it was fine.

  • Keep in mind, depending on the versions of the templates you have it looks like an empty tag is inserted for JavaMaximumHeapSize, if you insert your setting before that one, I think it is replacing your larger value with the default value when it hits that line, so search your csproj for other occurrences of JavaMaximumHeapSize. This has burned me a few times recently.

  • BrandonBooneBrandonBoone USMember ✭✭

    I am using Xamarin and I pull
    in my Main.axml file and i still get the

    File not found: C:\Users\blank\Desktop\WPB_Noise\WPB_Noise\COMPILETODALVIK

  • PaulAxtenPaulAxten GBMember ✭✭

    You can also set the Java heap size / arguments in the build settings section (right click on project in solution explorer, Options/Android Build/Advanced Tab :) Setting the heap to 1G there solved it for me.

  • jameszhoujameszhou CNMember ✭✭

    it seems that 1G JavaMaximumHeapSize still not enough to my app building. How can I increase the size more e.g. 2G as I have 8G memory in the Windows

    If I have to install 64 bit Java to get more heap size, is there any settings to configure to tell Xamarin use the 64-bit Java?

  • GabaSoftGabaSoft USMember

    i have a list with 20 items. each item has a frame with some text.
    i have changed the to 1g and even to 2g.
    but nothing helped me.

    plz some one help me.

  • flipm0deflipm0de BGMember ✭✭

    Same thing here. The same project was working fine before upgrading Xamarin. Now 1G or 2G does not help at all.

  • flipm0deflipm0de BGMember ✭✭

    So my research led me to the point that if I upgrade the Facebook SDK component from to the latest version I start getting this error no matter what version of Xamarin.Android I am using.

  • JesseLibertyJesseLiberty USInsider, University ✭✭✭
    edited June 2016

    @JonathanPryor Brilliant


    worked perfectly. Thanks!

  • KennyDeKennyDe BEUniversity

    1G worked perfectly for me too!

  • ViniciusSchneiderViniciusSchneider USMember ✭✭

    In a new Hello World PCL XAML Blank project, when you just upgrade Xamarin Forms to you will need increase the java heap.. :(

  • VictorHGarciaVictorHGarcia USUniversity ✭✭

    @ViniciusSchneider to how much you increased it? I put 1G and I'm still getting the error:

    C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets (1853, 3)
    java.lang.OutOfMemoryError. Consider increasing the value of $(JavaMaximumHeapSize)

    Any suggestions?

  • ViniciusSchneiderViniciusSchneider USMember ✭✭

    Just 1G and worked for me. I tried another values in the past but was not accepted. I did not found documentation about the valid values.

    @VictorHGarcia said:
    @ViniciusSchneider to how much you increased it? I put 1G and I'm still getting the error:

    C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets (1853, 3)
    java.lang.OutOfMemoryError. Consider increasing the value of $(JavaMaximumHeapSize)

    Any suggestions?

  • HefinSankalaHefinSankala USMember
    edited July 2016

    yep 1G worked for me to. Going over 1G always failed :(

  • Thanks the 1G solution worked.

  • _GT__GT_ USMember

    For me 1G worked. Thanks.

  • DonaldLearyDonaldLeary USMember

    worked for me! Thank you

  • MeigstonMeigston USMember ✭✭

    Worked for me! Thank you

  • Ajay_SBSICAjay_SBSIC USMember ✭✭✭

    Many Thanks to JonathanPryor

  • Followed Mark Cerezo order of operations and all is good now. Thanks!

  • prjcodeprjcode USMember

    While i was struggling a long time on this, and i also changed the heap size to 1GB, the only simple and stupid solution that helped in this, was "Clean Solution", it looks that moving from "Release" to "Debug" or the other way, affects each other in some way that should be fixing.
    Again "Clean Solution" command solved my head scratching annoying bug.

Sign In or Register to comment.