This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 8137 - CompileToDalvik failed
: CompileToDalvik failed
Product: Android
Classification: Xamarin
Component: MSBuild
: 4.2.x
: PC Windows
: --- normal
: ---
Assigned To: dean.ellis
  Show dependency treegraph
Reported: 2012-11-01 10:51 EDT by jkolb
Modified: 2013-11-20 12:43 EST (History)
4 users (show)

See Also:


Comment 1 jkolb 2012-11-01 10:54:29 EDT
Unfortunately I can't attach my project as it's too large.
Comment 2 Jonathan Pryor 2012-11-01 19:16:39 EDT
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 jkolb 2012-11-01 19:33:25 EDT
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 EDT How big are the .jar files you're referencing?
Comment 6 jkolb 2012-11-02 11:11:35 EDT
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 EDT
Indeed, but ~6MB? that's...really not that big.
Comment 8 jkolb 2012-11-02 11:24:33 EDT
Comment 9 Jonathan Pryor 2012-11-02 13:23:26 EDT
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 EST
Fixed in master/169162bacf
Comment 14 dean.ellis 2012-11-08 07:26:03 EST
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 jkolb 2012-11-12 14:07:44 EST
Will these be set in the UI somewhere?
Comment 16 Jonathan Pryor 2012-11-12 16:33:05 EST
> 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 jkolb 2012-11-13 11:24:58 EST
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 EST
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 EST
*** Bug 14147 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.