Bug 8137

Summary: CompileToDalvik failed
Product: Android Reporter: Jeremy Kolb <jkolb>
Component: MSBuildAssignee: dean.ellis
Severity: normal CC: atsushi, jonp, mono-bugs+monodroid, peter.collins, toopge
Priority: ---    
Version: 4.2.x   
Target Milestone: ---   
Hardware: PC   
OS: Windows   
Tags: Is this bug a regression?: ---
Last known good build:

Comment 1 Jeremy Kolb 2012-11-01 10:54:29 UTC
Unfortunately I can't attach my project as it's too large.
Comment 2 Jonathan Pryor 2012-11-01 19:16:39 UTC
The problem isn't in your project, per-se. The problem is that your project is "huge," and is causing the Android SDK dx.jar program to consume so much memory that it runs out of heap, triggering a java.lang.OutOfMemoryError.

Apparently the fix is to use `java -Xmx1GB` to raise the maximum amount of heap memory that Java will use. (That's assuming that 1GB is even enough.) (What is this, System 7?!)

Unfortunately there's no workaround; the command line is generated, and there are no environment variables that java.exe uses to specify the maximum heap size. :-/
Comment 4 Jeremy Kolb 2012-11-01 19:33:25 UTC
Wow... I didn't think it was that big really.  I mean I knew that implementing Plan 9 was going to be a pain but I figured that since been around for about 20 years I'd be ok.

Just kidding.  My main project only has about 24 classes in it.  Then I have 3 jar bindings and NettopologySuite (which is pretty large).  I don't think that's too unreasonable.
Comment 5 Jonathan Pryor 2012-11-01 19:39:10 UTC
jkolb@ara.com: How big are the .jar files you're referencing?
Comment 6 Jeremy Kolb 2012-11-02 11:11:35 UTC
osmdroid-android-3.0.8.jar is 263KB
osmdroid-third-party-3.0.8.jar is 20 KB
droidText.0.2.jar is 6450KB

I suspect that droidText was sending it over the limit.
Comment 7 Jonathan Pryor 2012-11-02 11:23:51 UTC
Indeed, but ~6MB? that's...really not that big.
Comment 8 Jeremy Kolb 2012-11-02 11:24:33 UTC
Comment 9 Jonathan Pryor 2012-11-02 13:23:26 UTC
dellis: Related task: all MSBuild tasks that invoke java.exe should also take a $(JavaMaximumHeapSize) and/or $(JavaOptions) parameter, which would be added to the java.exe command line.
Comment 13 dean.ellis 2012-11-06 13:42:54 UTC
Fixed in master/169162bacf
Comment 14 dean.ellis 2012-11-08 07:26:03 UTC
The fix adds two additional build parameters to the .targets
file for CompileToDalvik and for completeness JarToXml.
The new parameters are

* JavaMaximunHeapSize - This allows the overriding of the
  default java heapsize which is sometimes too low to compile
  some .jar files.
  Parameter can be set by providing the following to msbuild


* JavaOptions - This allows any other additional parameters
 to be passed to the java application.
 Parameter can be set by providing the following to msbuild

Comment 15 Jeremy Kolb 2012-11-12 14:07:44 UTC
Will these be set in the UI somewhere?
Comment 16 Jonathan Pryor 2012-11-12 16:33:05 UTC
> Will these be set in the UI somewhere?

Not at this time; we've entered UI freeze for the next version of our products.

I've added bugs to track the UI changes:
* Bug #8352: Update MonoDevelop
* Bug #8353: Update VS
Comment 17 Jeremy Kolb 2012-11-13 11:24:58 UTC
Ok that's fine (I'm assuming there's another way to specify these values?).  This is a blocker for me so as soon as I can get it working with the next version the happier I'll be.
Comment 18 Jonathan Pryor 2012-11-13 11:31:29 UTC
The "other way" to specify these values will be to edit the .csproj in e.g. an XML editor (VS will do ;-), and add:


Or (as mentioned in Comment #14) you can use MSBuild directly:

    msbuild /p:JavaMaximumHeapSize=1G Project.csproj /t:SignAndroidPackage # ...
Comment 19 Peter Collins 2013-11-20 12:43:11 UTC
*** Bug 14147 has been marked as a duplicate of this bug. ***
Comment 20 Tom Opgenorth 2017-05-25 16:53:40 UTC
*** Bug 7039 has been marked as a duplicate of this bug. ***