locked
"java.exe" exited with code 2. RRS feed

  • Question

  • User73113 posted

    I added Google play services to my project for maps but now keep getting this error "java.exe" exited with code 2. I am not sure if it is different from "java.exe" exited with code 1 but I have tried all the suggestions online My heap size is 1G. My target version is 21, I have clean rebuild etc.. When I click on the error it takes me to this CompileToDalvik. How can I resolve this? Even if I remove google play services I still get this error( clean / refresh rebuild etc..)

    Sunday, July 26, 2015 11:50 PM

All replies

  • User131987 posted

    I ran into this exact problem a while ago. You've reached the Dalvik 65k limit, probably because you added in Google play services, which eats up around 21k of your 65k allowance.

    Here are some articles that might help you out with this:

    https://medium.com/@rotxed/dex-skys-the-limit-no-65k-methods-is-28e6cb40cf71

    https://developer.android.com/intl/ko/tools/support-library/features.html#multidex

    http://android-developers.blogspot.co.il/2011/07/custom-class-loading-in-dalvik.html

    http://www.infragistics.com/community/blogs/graham/archive/2015/02/06/flexing-xamarin-android-s-build-to-work-around-android-s-65k-method-limitation.aspx

    Unfortunately the Google option (the DEX solution mentioned in those links) isn't available to Xamarin. If the map isn't crucial to your app and you don't mind launching a maps instance in the browser/maps app on phone I would do that.

    Tuesday, July 28, 2015 8:37 AM
  • User35290 posted

    There is an option in the project properties called "Enable Multi-Dex". Have you tried that option?

    AndroidEnableMultiDex: A boolean property that determines whether or not multi-dex support will be used in the final .apk. Support for this property was added in Xamarin.Android 5.1.

    Tuesday, July 28, 2015 8:48 AM
  • User73113 posted

    thank you I will try the suggestions and let you know

    Friday, July 31, 2015 8:32 AM
  • User147194 posted

    @charl, Have you resolved that problem ? Any updates ? I'm facing same issue too.

    Tuesday, August 18, 2015 2:20 AM
  • User73113 posted

    Hi I have not tried the following yet (did not have time) but this was suggested form. I only need maps and location suggested I remove google play store and download only these two. I am going to test this later today. hope it helps https://www.nuget.org/packages/Xamarin.GooglePlayServices.Location/ https://www.nuget.org/packages/Xamarin.GooglePlayServices.Maps/

    Tuesday, August 18, 2015 7:07 AM
  • User156371 posted

    @Droid - your suggestion worked out for me! thx much.

    Thursday, November 5, 2015 10:10 PM
  • User21550 posted

    I'm getting the same. so I set enable multi-dex but now I'm getting

    CREATEMULTIDEXMAINDEXCLASSLIST : error : Expecting class path separator ';' before '\Android\android-sdk\build-tools\23.0.0\lib\shrinkedAndroid.jar' in argument number 8

    im using the latest stable V2.* and V26 of googleplayservices.

    Wednesday, November 18, 2015 5:02 AM
  • User66025 posted

    There is a bug already reported to Xamarin :

    Bug 33052 - The option for multi-dex fails when the path to the Android SDK contains a space

    Wednesday, November 18, 2015 12:39 PM
  • User137312 posted

    Tuesday, October 4, 2016 9:58 AM
  • User254912 posted

    Enable Multi-Dex and Proguard options in Android Option in Xamarin.Android project properties. After this if you build it will throw "Expecting class path separator ';' before '\Android\android-sdk\build-tools\23.0.1\lib\shrinkedAndroid.jar' in argument number 8". Change SDK path to C:/Android/Androidsdk. As because C:/Program Files contains space ie why it gives that error. After that change Android SDK Path to the new directory in Visaul Studio/Tools/Options/Xamarin/Android Settings

    Thursday, January 5, 2017 10:00 AM
  • User124403 posted

    FYI, there is another situation involving Multi-Dex, causing that java error 2. SOLUTION To use Google Play Services with Nougat/API 24+, do 3 things: (1) Use 64-bit Java JDK 1.8, (2) Check Enable Multi-Dex in Tools/Options. (3) Replace ProGuard jar files (multi-dex is part of proguard), as described in update Android SDK with latest Proguard.

    Wednesday, February 8, 2017 10:45 PM
  • User287127 posted

    I got the same issue , I solved it by enable Multi-Dex

    Wednesday, February 8, 2017 11:24 PM
  • User124403 posted

    @"minaFawzy.1775" (but mostly so anyone who comes along will know it is a solved problem) - FWI - Indeed, that is the summary of this thread - the solution is to Enable Multi-Dex. Other posts are about situations where some people need to make other changes also, because enabling multi-dex resulted in new symptoms/problems.

    Saturday, February 11, 2017 10:13 PM
  • User313837 posted

    I had the same problem after installing Xamarin.GooglePlayServices.Ads. A solutions with dex did not work until I had remove Xamarin.GooglePlayServices.Ads and I remained with Xamarin.GooglePlayServices.Ads.Lite. It works wit PCL project and Xamarin.GooglePlayServices v42.1021.1.

    Saturday, May 13, 2017 11:15 AM
  • User250130 posted

    Enabled ProGuard with no success, then MultiDex and I'm good to go ... But the thing I do not understand is that I don't have that many packages ... Maybe this is because I have a PCL project ? Or because I have some big packages like some of Firebase and of GooglePlayServices ?

    Is there a place I can see how much methods a package is using ? I'd like to know

    And does multidex impact apk size or app performances ?

    Thanks in advance,

    Tuesday, May 30, 2017 3:19 PM
  • User288368 posted

    I have just had this issue and the problem was java jdk version 9.0.1, reverted to version 8 and all ok.

    Sunday, October 22, 2017 2:01 PM
  • User226914 posted

    Any word on compatibility with JDK 9.0.x?

    Monday, October 23, 2017 9:19 PM