Hi, I'm trying to bind BurstlySDK to my mono for Android project.
According to the steps described here http://docs.xamarin.com/guides/android/advanced_topics/java_integration_overview/binding_a_java_library_(.jar)
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:
COMPILETODALVIK : UNEXPECTED TOP-LEVEL error :
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2882)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:390)
at java.lang.StringBuilder.append(StringBuilder.java:119)
at com.android.dx.rop.type.Prototype.withFirstParameter(Prototype.java:370)
at com.android.dx.rop.type.Prototype.intern(Prototype.java:180)
at com.android.dx.cf.iface.StdMethod.<init>(StdMethod.java:45)
at 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:532)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:396)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:378)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:241)
at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:112)
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)
Googling only finds this: https://code.google.com/p/android/issues/detail?id=20814 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!
Posts
Ok, so even after I remove all nodes with
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 inobj/Debug/generated/
Another solution could be to increase Java heap space with
but where can one edit this for Mono?
In some places including here http://stackoverflow.com/questions/1434779/maximum-java-heap-size-of-a-32-bit-jvm-on-a-64-bit-os 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 http://forum.xda-developers.com/showthread.php?t=761183 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.
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.
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.
I don't know if this will fix your issue, but to change the heap size you can use
_JAVA_OPTIONS
Not well documented and not standard, I guess, but it seems to work.
https://forums.oracle.com/forums/thread.jspa?messageID=5203488
http://stackoverflow.com/questions/9677346/java-system-environment-variable
http://docs.oracle.com/javase/1.5.0/docs/guide/2d/flags.html
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.
As of Xamarin.Android 4.6, you can provide the
$(JavaMaximunHeapSize)
and$(JavaOptions)
MSBuild properties to let Java allocate enough memory to complete your build.You can do this by hand-editing your
.csproj
and adding the following section:Thanks!
The solution to add
_JAVA_OPTIONS
environment variable with value-Xmx1g
worked.Hover, adding the
JavaMaximumHeapSize
tag into the .proj file didn't help.I added the property right in the beginning of the file. Is this the right way to do it?
It would or course be preferable to have this setting right in the proj file so that anyone else working on the project would have this working out of the box.
<JavaMaximunHeapSize/>
is mis-spelled; it should be<JavaMaximumHeapSize/>
(noten
vs.m
). (Because I mis-spelled it originally. Oops. Corrected.)Sorry, I didn't notice that, too. Thx
Nice. What's the default value? Getting a heap memory exception on a 64 bit OSX with plenty of memory is just wrong.
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.
I don't know, but it certainly looks like it.
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 me.you saved my time.thank you...
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.
I am using Xamarin and I pull
1G
in my Main.axml file and i still get the
File not found: C:\Users\blank\Desktop\WPB_Noise\WPB_Noise\COMPILETODALVIK
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.
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?
Worked for me. In my case (VS 2013 PCL Project) I did it in the property page of the project. Double click in 'Properties' in the Solution Explorer, then Click on 'Android Options' and click in 'Advanced' tab. There you find 'Java max Heap Size', write 1G and save. It will modify the *.csproj file.
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.
Same thing here. The same project was working fine before upgrading Xamarin. Now 1G or 2G does not help at all.
So my research led me to the point that if I upgrade the Facebook SDK component from 4.13.1.0 to the latest version I start getting this error no matter what version of Xamarin.Android I am using.
@JonathanPryor Brilliant
worked perfectly. Thanks!
1G worked perfectly for me too!
In a new Hello World PCL XAML Blank project, when you just upgrade Xamarin Forms to 2.3.0.107 you will need increase the java heap..
@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?
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.
yep 1G worked for me to. Going over 1G always failed
Thanks! It was the correct fix.
Here's the steps I did:
1. Closed the VS2015
2. Changed the file .csproj
3. Re-open VS2015
4. Re-build
5. Done!
Thanks the 1G solution worked.
For me 1G worked. Thanks.
worked for me! Thank you
Worked for me! Thank you
Many Thanks to JonathanPryor
Followed Mark Cerezo order of operations and all is good now. Thanks!
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.