“java.exe” exited with code 2 Xamarin.Android project

后端 未结 14 2104
生来不讨喜
生来不讨喜 2020-12-05 04:38

so I have my Xamarin.Android project which contains several libraries. When I try to build I receive an error which says \"java.exe\" exited with code 2.

After some

相关标签:
14条回答
  • 2020-12-05 04:51

    I've struggled with this issue for quite a long time. I found source of the error in signing - as I cloned project repo from company TFS, Android csproj file had entries for KeyStore settings and location. I didn't have the keystore and the location on my drive was invalid. Visual Studio is then unable to sign the app while deploying and instead of some sort of FileNotFoundException it gave me just java exited with code 2. So...

    tl;dr: Go to android project properties, select package signing a uncheck "Sign the apk file..." (which changes csproj <AndroidKeyStore>true</AndroidKeyStore> to false) and voila, you can now run your solution.

    0 讨论(0)
  • 2020-12-05 04:52

    In my case the one of keystore details was wrong, after saving-> cleaning -> building process it worked.

    0 讨论(0)
  • 2020-12-05 04:55

    Please Update your Visual Studio to Latest version, if you are still using an old version.

    If you think there is no solution then go and enable the Multidex

    0 讨论(0)
  • 2020-12-05 04:57

    My experience is...

    I updated the following elements:

    • Xamarin.Android.Support.Design
    • Xamarin.Android.Support.v4
    • Xamarin.Android.Support.v7.AppCompat
    • Xamarin.Android.Support.v7.CardView
    • Xamarin.Android.Support.v7.MediaRouter

    from 26.1.0.1 to 28.0.0.3

    Then, after it started the issue with:

    "java.exe" exited with code 2 Xamarin.Android project.

    I just ticked the Enable Multi-Dex inside the Android project property. I am using VS 2017 in windows system.

    0 讨论(0)
  • 2020-12-05 04:59

    After finding this question and @Daniel_97s answer I was able to solve this error only by adding multidex to the project without changing MainDexClasses.bat:

    1. Check the option in Project Options:

    1. Add MultiDexApplication to Android Manifest:

      <application android:name="android.support.multidex.MultiDexApplication"></application>
      

    Note I was getting this error code 2 on Visual Studio for Mac and on Windows the same app was building successfully. (why?)

    0 讨论(0)
  • 2020-12-05 05:04

    Found the answer after about 20 hours of searching in my project.. So here are the steps to resolve the problem "java.exe" exited with code 2

    1) Change the MainDexClasses.bat as described in the link:

    http://www.jon-douglas.com/2016/09/05/xamarin-android-multidex/

    2) Make sure you have enabled Multidex Option in your Android Application! Have a look at the .csprj file if Multidex is set to true (in my case it wasn't even if I enabled Multidex)

    3) Add the following part in your AndroidManifest file

    <application android:name="android.support.multidex.MultiDexApplication"></application>
    

    This will tell your Android project to actually use the Multidex-Option given.

    After a clean and build I was able to run my application as it is.

    0 讨论(0)
提交回复
热议问题