“java.exe”退出代码 2 Xamarin.Android 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44004161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 01:16:46  来源:igfitidea点击:

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

javaandroidxamarinxamarin.androidandroid-multidex

提问by Daniel_97

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.

所以我有我的 Xamarin.Android 项目,其中包含多个库。当我尝试构建时,我收到一个错误,提示“java.exe”以代码 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/

经过几个小时的谷歌研究,我发现我可以启用 Multidex。根据 Jon Doublas 的博客条目,我执行了提到的步骤。 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.

根据博客条目 Android API Level > 21 处理 Multidex 本身。好吧,我的经验是它没有。我在 API 级别 25 上构建并使用相同的信息一次又一次地得到相同的错误。文章中的步骤没有帮助。Xamarin.Android 似乎不支持 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?

似乎您必须自己处理 Multidex,但我还没有找到任何有效的解决方案。有人找到了有效的解决方案吗?

I am using Xamarin 4.6 and Visual studio 2017.

我正在使用 Xamarin 4.6 和 Visual Studio 2017。

采纳答案by Daniel_97

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

在我的项目中搜索了大约 20 个小时后找到了答案..所以这里是解决“java.exe”以代码 2 退出的问题的步骤

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

1) 按照链接中的描述更改 MainDexClasses.bat:

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

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

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

2) 确保您已Multidex在 Android 应用程序中启用Option!查看.csprj文件 ifMultidex设置为true(在我的情况下,即使我启用它也不是Multidex

3) Add the following part in your AndroidManifestfile

3)在您的AndroidManifest文件中添加以下部分

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

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

这将告诉您的 Android 项目实际使用给定的 Multidex-Option。

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

经过清理和构建后,我能够按原样运行我的应用程序。

回答by Micer

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:

在找到这个问题和@Daniel_97s 的答案后,我只能通过在项目中添加 multidex 而不更改 MainDexClasses.bat 来解决这个错误:

  1. Check the option in Project Options:
  1. 检查项目选项中的选项:

Check the option in Project Options:

检查项目选项中的选项:

  1. Add MultiDexApplicationto Android Manifest:

    <application android:name="android.support.multidex.MultiDexApplication"></application>
    
  1. 添加MultiDexApplication到 Android 清单:

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

请注意,我在 Visual Studio for Mac 上收到此错误代码 2,在 Windows 上成功构建了相同的应用程序。(为什么?)

回答by Vermoric Huynh

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

我只去 option > Build > Android Build 并选中 Enable Multi-Dex 它将解决

回答by Hein Andre Gr?nnestad

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.

我的解决方案是禁用“使用以下密钥库详细信息签署 .APK 文件”。由于密钥库位置和/或密码不正确,java.exe 以代码 2 退出。

enter image description here

在此处输入图片说明

回答by Zumry Mohamed

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

如果您仍在使用旧版本,请将您的 Visual Studio 更新到最新版本。

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

如果您认为没有解决方案,那么请启用 Multidex

回答by Starlin González

Reassign the path of the keystore worked for me

重新分配密钥库的路径对我有用

==EDIT 01==

==编辑01==

Double click on Android Project > Android Package Signing

双击 Android 项目 > Android 包签名

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

在 Keystore 路径上,不知道为什么,但显然路径错误,我再次从同一路径重新选择 .keystore 文件,“以代码 2 退出”的错误消失了,我能够存档以供发布

回答by 100RaBH

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

在我的情况下,密钥库详细信息之一是错误的,在保存-> 清理-> 构建过程后它起作用了。

回答by Filipe Piletti Plucenio

Try reset the keystore <AndroidSigningKeyStore>or change to false the key

尝试重置密钥库<AndroidSigningKeyStore>或将密钥更改为 false

>

>

<AndroidKeyStore>true</AndroidKeyStore>

Only to check. But remembering that it needs to be set to true.

只能检查。但请记住,它需要设置为 true。

After Clean and Rebuild the solution.

清洁并重建解决方案后。

回答by Le-roy Staines

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

我的.csproj文件中有一个不再有效的KeyStore条目,甚至认为右键单击该项目并检查属性表明我已将其指向新位置。

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

在 .csproj 中查找所有实例<AndroidSigningKeyStore>并相应地更新。

回答by Klemikaze

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

我已经在这个问题上挣扎了很长时间。我在签名时发现了错误的来源 - 当我从公司 TFS 克隆项目 repo 时,Android csproj 文件有 KeyStore 设置和位置的条目。我没有密钥库,驱动器上的位置无效。然后,Visual Studio 在部署时无法对应用程序进行签名,而不是某种 FileNotFoundException,它给了我只用代码 2 退出的 java。所以......

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.

tl; dr:转到android项目属性,选择包签名取消选中“签署apk文件...”(将csproj更改<AndroidKeyStore>true</AndroidKeyStore>为false),瞧,您现在可以运行您的解决方案。

enter image description here

在此处输入图片说明