Bug 8137 - CompileToDalvik failed
Summary: CompileToDalvik failed
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild (show other bugs)
Version: 4.2.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: dean.ellis
URL:
: 7039 14147 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-11-01 10:51 UTC by Jeremy Kolb
Modified: 2017-05-25 16:53 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

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
Exactly
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

  /p:JavaMaximumHeapSize="800m"

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

 /p:JavaOptions="-Xbatch"
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:

    <PropertyGroup>
        <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
    </PropertyGroup>

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. ***

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.


Create a new report for Bug 8137 on Developer Community or GitHub if you have new information to add and do not yet see a matching report.

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments


Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Related Links: