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

无人久伴 提交于 2019-12-17 15:49:06

问题


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 hours of google research I found out that I could enable Multidex. According to the blog entry of Jon Doublas I did the steps mentioned. http://www.jon-douglas.com/2016/09/05/xamarin-android-multidex/

According to the blog entry Android API Level > 21 handles Multidex itself. Well my experience is that it does not. I am building on API Level 25 and get the same error again and again with the same information. The steps in the article do not help. It seems like Xamarin.Android does not support Multidex.

It seems like you have to handle Multidex by yourself but I haven't found any solution which is working. Dos anybody found a solution which works?

I am using Xamarin 4.6 and Visual studio 2017.


回答1:


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.




回答2:


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?)




回答3:


The solution in my case was to disable the "Sign the .APK file using the following keystore details". Because the keystore location and/or password was incorrect, java.exe exited with code 2.




回答4:


I only go to option > Build > Android Build and check Enable Multi-Dex it will resolve




回答5:


My .csproj file had an entry for the KeyStore that was no longer valid, even thought right-clicking the project and inspecting the properties indicated that I had pointed it to the new location.

Within .csproj look for all instances of <AndroidSigningKeyStore> and update accordingly.




回答6:


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.




回答7:


Reassign the path of the keystore worked for me

==EDIT 01==

Double click on Android Project > Android Package Signing

On the Keystore path, don't know why but apparently the path was wrong, I re-select the .keystore file again from the same path, and the error "exited with code 2" went away and I was able to Archive for release




回答8:


Disable sign the .APK file using the following keystore details as @Klemikaze




回答9:


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




回答10:


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




回答11:


Try reset the keystore or change to false the key true. Only to check. But remembering that it needs to be set to true.




回答12:


I had this error when switching from VS Mac to VS Windows.

Here the topic Switching From VS Mac To VS Windows got “java.exe” exited with code 2

The issue was comming from the Android.csproj and the Keystore Path.
It was set to my Mac Path even if I changed it on

VSWindows AndroidProject => Properties => Signin

So I removed this lines on Android.csproj (edited with third text editor):

<AndroidKeyStore>True</AndroidKeyStore>
<AndroidSigningKeyStore>YourMacPath/Alias.keystore</AndroidSigningKeyStore>
<AndroidSigningStorePass>Password</AndroidSigningStorePass>
<AndroidSigningKeyAlias>Alias</AndroidSigningKeyAlias>
<AndroidSigningKeyPass>AliasPassword</AndroidSigningKeyPass>

On debug & release Part.

Then you can edit them on VS Windows.

Hope I helped someone. See ya




回答13:


In my case this was link to the "Sign the .APK file using the following keystore details" option as Hein Andre Grønnestad mentioned. The location was not correct.

I wanted to put a path that could work for everyone at work so I used $HOME/Library/... instead of /Users/Me/Library/...

The problem is $HOME doesn't mean anything special for java so the keystore file could not be found.

Solution: use relative path or absolute path without $HOME variable or ~



来源:https://stackoverflow.com/questions/44004161/java-exe-exited-with-code-2-xamarin-android-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!