Java.exe在VS 2015中构建的Android应用程序中以代码2退出

时间:2017-04-11 10:07:21

标签: xamarin visual-studio-2015 xamarin.android android-multidex

我在VS2015中使用xamarin构建了一个Android应用程序。我能够在谷歌播放服务上发布第一版的应用程序。

前几天,我尝试修复问题并修改了一些UI,添加了一些xml文件和活动。

但是当我构建项目时,我在调试模式下得到了错误java.exe退出代码2,而在发布模式下构建成功。

我尝试将HeapSize 1G改为2G发现没有区别。 我尝试启用ProGuard但默认情况下已禁用。 我经历了启用MultiDex,它导致另一个错误,即文件未找到错误。 我甚至尝试删除bin和obj文件夹并重新重建但没有运气!

这是错误

    Severity    Code    Description Project File    Line    Suppression State
Error       "java.exe" exited with code 2.  WebSchoolAndroid    C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets   2152    

在第2152行我有

 <!-- Compile java code to dalvik -->
  <CompileToDalvik 
    Condition="'$(UseJackAndJill)'!='True'"
    DxJarPath="$(DxJarPath)"
    JavaToolPath="$(JavaToolPath)"
    JavaMaximumHeapSize="$(JavaMaximumHeapSize)"
    JavaOptions="$(JavaOptions)"
    ClassesOutputDirectory="$(IntermediateOutputPath)android\bin\classes"
    ToolPath="$(DxToolPath)"
    ToolExe="$(DxToolExe)"
    UseDx="$(UseDx)"
    MultiDexEnabled="$(AndroidEnableMultiDex)"
    MultiDexMainDexListFile="$(_AndroidMainDexListFile)"
    JavaLibrariesToCompile="@(_JavaLibrariesToCompileForAppDx)"
    OptionalObfuscatedJarFile="$(IntermediateOutputPath)proguard\__proguard_output__.jar"
  />

来自诊断输出

  C:\Program Files (x86)\Java\jdk1.8.0_101\\bin\java.exe -Xmx1G -jar C:\Users\user\AppData\Local\Xamarin\Universal\AndroidSDK\build-tools\24.0.3\\lib\dx.jar --no-strict --dex --output=obj\Debug\android\bin obj\Debug\android\bin\classes "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v6.0\mono.android.jar" obj\Debug\__library_projects__\PdfViewBinding\library_project_imports\bin\android-pdfview.jar obj\Debug\__library_projects__\PhotoViewBinding\library_project_imports\bin\photoview.jar obj\Debug\__library_projects__\Square.OkHttp\library_project_imports\okhttp-2.4.0.jar obj\Debug\__library_projects__\Square.OkIO\library_project_imports\okio-1.5.0.jar obj\Debug\__library_projects__\Square.Picasso\library_project_imports\picasso-2.5.2.jar obj\Debug\__library_projects__\UrlImageViewHelper\library_project_imports\bin\classes.jar obj\Debug\__library_projects__\WebSchoolAndroid.Bindings\library_project_imports\skyepub.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.Animated.Vector.Drawable\24.2.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.Compat\24.2.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.Compat\24.2.1\embedded\libs\internal_impl-24.2.1.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.Core.UI\24.2.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.Core.UI\24.2.1\embedded\libs\internal_impl-24.2.1.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.Core.Utils\24.2.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.Core.Utils\24.2.1\embedded\libs\internal_impl-24.2.1.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.Design\24.2.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.Fragment\24.2.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.Fragment\24.2.1\embedded\libs\internal_impl-24.2.1.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.Media.Compat\24.2.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.Media.Compat\24.2.1\embedded\libs\internal_impl-24.2.1.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.v4\24.2.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.v7.AppCompat\24.2.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.v7.CardView\24.2.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.v7.RecyclerView\24.2.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Android.Support.Vector.Drawable\24.2.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Firebase.Common\9.6.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Firebase.Iid\9.6.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.Firebase.Messaging\9.6.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.GooglePlayServices.Base\9.6.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.GooglePlayServices.Basement\9.6.1\embedded\classes.jar C:\Users\user\AppData\Local\Xamarin\Xamarin.GooglePlayServices.Tasks\9.6.1\embedded\classes.jar  (TaskId:294)
1>   (TaskId:294)
1>  trouble writing output: Too many field references: 65549; max is 65536. (TaskId:294)
1>  You may try using --multi-dex option. (TaskId:294)
1>  References by package: (TaskId:294)
1>       2 android.accounts (TaskId:294)
1>      29 android.app (TaskId:294)
1>       1 android.content (TaskId:294)
1>      32 android.content.pm (TaskId:294)
1>       9 android.content.res (TaskId:294)
1>       3 android.database (TaskId:294)
1>      51 android.graphics (TaskId:294)
1>       2 android.media (TaskId:294)
1>       1 android.media.browse (TaskId:294)
1>       2 android.net (TaskId:294)
1>      17 android.os (TaskId:294)
1>       3 android.print (TaskId:294)
1>       1 android.provider (TaskId:294)
1>       8 android.runtime (TaskId:294)
1>    2410 android.support.compat (TaskId:294)
1>    2410 android.support.coreui (TaskId:294)
1>    2410 android.support.coreutils (TaskId:294)
1>    2410 android.support.design (TaskId:294)
1>      58 android.support.design.internal (TaskId:294)
1>     679 android.support.design.widget (TaskId:294)
1>    2410 android.support.fragment (TaskId:294)
1>    2563 android.support.graphics.drawable (TaskId:294)
1>    2410 android.support.graphics.drawable.animated (TaskId:294)
1>    2410 android.support.mediacompat (TaskId:294)
1>    2410 android.support.v4 (TaskId:294)
1>      13 android.support.v4.accessibilityservice (TaskId:294)
1>      17 android.support.v4.animation (TaskId:294)
1>     863 android.support.v4.app (TaskId:294)
1>     111 android.support.v4.content (TaskId:294)
1>       1 android.support.v4.content.pm (TaskId:294)
1>       1 android.support.v4.content.res (TaskId:294)
1>       9 android.support.v4.graphics (TaskId:294)
1>      41 android.support.v4.graphics.drawable (TaskId:294)
1>       4 android.support.v4.hardware.display (TaskId:294)
1>      12 android.support.v4.hardware.fingerprint (TaskId:294)
1>      10 android.support.v4.internal.view (TaskId:294)
1>     350 android.support.v4.media (TaskId:294)
1>     300 android.support.v4.media.session (TaskId:294)
1>       7 android.support.v4.net (TaskId:294)
1>      19 android.support.v4.os (TaskId:294)
1>      63 android.support.v4.print (TaskId:294)
1>       9 android.support.v4.provider (TaskId:294)
1>      55 android.support.v4.text (TaskId:294)
1>       6 android.support.v4.text.util (TaskId:294)
1>     102 android.support.v4.util (TaskId:294)
1>     433 android.support.v4.view (TaskId:294)
1>     137 android.support.v4.view.accessibility (TaskId:294)
1>       8 android.support.v4.view.animation (TaskId:294)
1>     495 android.support.v4.widget (TaskId:294)
1>     397 android.support.v7.app (TaskId:294)
1>    2410 android.support.v7.appcompat (TaskId:294)
1>    2410 android.support.v7.cardview (TaskId:294)
1>       8 android.support.v7.content.res (TaskId:294)
1>      18 android.support.v7.graphics.drawable (TaskId:294)
1>    2410 android.support.v7.recyclerview (TaskId:294)
1>       1 android.support.v7.text (TaskId:294)
1>       2 android.support.v7.transition (TaskId:294)
1>     124 android.support.v7.util (TaskId:294)
1>      77 android.support.v7.view (TaskId:294)
1>     248 android.support.v7.view.menu (TaskId:294)
1>    1398 android.support.v7.widget (TaskId:294)
1>      89 android.support.v7.widget.helper (TaskId:294)
1>       1 android.support.v7.widget.util (TaskId:294)
1>       5 android.text (TaskId:294)
1>       1 android.text.util (TaskId:294)
1>      14 android.util (TaskId:294)
1>      18 android.view (TaskId:294)
1>       8 android.view.accessibility (TaskId:294)
1>       1 android.view.inputmethod (TaskId:294)
1>       5 android.webkit (TaskId:294)
1>      21 android.widget (TaskId:294)
1>    2404 com.google.android.gms (TaskId:294)
1>      20 com.google.android.gms.actions (TaskId:294)
1>      13 com.google.android.gms.ads.identifier (TaskId:294)
1>      36 com.google.android.gms.auth.api.signin (TaskId:294)
1>       6 com.google.android.gms.auth.api.signin.internal (TaskId:294)
1>    2404 com.google.android.gms.base (TaskId:294)
1>      98 com.google.android.gms.common (TaskId:294)
1>      95 com.google.android.gms.common.api (TaskId:294)
1>      41 com.google.android.gms.common.data (TaskId:294)
1>      46 com.google.android.gms.common.images (TaskId:294)
1>     188 com.google.android.gms.common.internal (TaskId:294)
1>       1 com.google.android.gms.common.internal.safeparcel (TaskId:294)
1>       4 com.google.android.gms.common.server (TaskId:294)
1>      12 com.google.android.gms.common.server.converter (TaskId:294)
1>      33 com.google.android.gms.common.server.response (TaskId:294)
1>      63 com.google.android.gms.common.stats (TaskId:294)
1>      22 com.google.android.gms.common.util (TaskId:294)
1>      27 com.google.android.gms.dynamic (TaskId:294)
1>       2 com.google.android.gms.dynamite.descriptors.com.google.android.gms.flags (TaskId:294)
1>      16 com.google.android.gms.flags.impl (TaskId:294)
1>       6 com.google.android.gms.iid (TaskId:294)
1>    1341 com.google.android.gms.internal (TaskId:294)
1>       5 com.google.android.gms.location.places (TaskId:294)
1>      18 com.google.android.gms.phenotype (TaskId:294)
1>      11 com.google.android.gms.playlog.internal (TaskId:294)
1>       6 com.google.android.gms.security (TaskId:294)
1>      26 com.google.android.gms.signin.internal (TaskId:294)
1>    2452 com.google.android.gms.tasks (TaskId:294)
1>    2435 com.google.firebase (TaskId:294)
1>       2 com.google.firebase.auth (TaskId:294)
1>    2459 com.google.firebase.iid (TaskId:294)
1>    2437 com.google.firebase.messaging (TaskId:294)
1>    2495 com.joanzapata.pdfview (TaskId:294)
1>       8 com.joanzapata.pdfview.model (TaskId:294)
1>      39 com.joanzapata.pdfview.util (TaskId:294)
1>    2492 com.koushikdutta.urlimageviewhelper (TaskId:294)
1>    1131 com.skytree.epub (TaskId:294)
1>     368 com.squareup.okhttp (TaskId:294)
1>      90 com.squareup.okhttp.internal (TaskId:294)
1>     133 com.squareup.okhttp.internal.http (TaskId:294)
1>       1 com.squareup.okhttp.internal.io (TaskId:294)
1>     243 com.squareup.okhttp.internal.spdy (TaskId:294)
1>      11 com.squareup.okhttp.internal.tls (TaskId:294)
1>     347 com.squareup.picasso (TaskId:294)
1>    2401 com.ytechwebschool.droid (TaskId:294)
1>       2 java.io (TaskId:294)
1>      12 java.lang (TaskId:294)
1>       7 java.lang.annotation (TaskId:294)
1>       6 java.net (TaskId:294)
1>       1 java.nio (TaskId:294)
1>       6 java.util (TaskId:294)
1>       4 java.util.concurrent (TaskId:294)
1>       3 java.util.logging (TaskId:294)
1>       2 md5019150c7713b24a447e4fd8c3f76632d (TaskId:294)
1>       2 md5048a04284979bff265231e98628579ce (TaskId:294)
1>       8 md520476b3d730a4692111560b01beafbf5 (TaskId:294)
1>       2 md5205d0916216d138654c77f637ee1cc90 (TaskId:294)
1>      12 md521020641efcec5bf9b0512907b92f249 (TaskId:294)
1>      10 md52335815dbfafa80b49f1a49c2a70d818 (TaskId:294)
1>       4 md526b7ac14cffc1a788e82c7b73f3add08 (TaskId:294)
1>       4 md531f8cc8d4d39b2fa02686ee0eb368905 (TaskId:294)
1>       8 md5471d110c8bb7ff37297374df784c2cee (TaskId:294)
1>       6 md55033ca37c678cdf20c14f110c9bacb80 (TaskId:294)
1>     178 md552b354c3816a29fbb90de6c8f0fdcd19 (TaskId:294)
1>       6 md552b8a35caf489e8e9cc4abcbc24b4c72 (TaskId:294)
1>       2 md55d8049a390a6f59c6033421d9a6a7cb8 (TaskId:294)
1>      18 md55f745489a55c1418869d471d93b5f35b (TaskId:294)
1>       4 md5636a41490577073255dce8c0a20bd415 (TaskId:294)
1>      10 md573df5bf65258bde5f06e24f6fe60f220 (TaskId:294)
1>       4 md5d0344be23ac987695f177aa1dab31949 (TaskId:294)
1>      16 md5de74fe60be74057a72a4e5ed2f8ed880 (TaskId:294)
1>       2 md5e424e6ea239d40c2a27b23ad851f2b02 (TaskId:294)
1>       4 md5ef453142d677b7c0ee97e9e15b9f6cda (TaskId:294)
1>       4 md5fb73fd704f950839995cd69b1931d746 (TaskId:294)
1>       6 mono (TaskId:294)
1>       2 mono.android.accounts (TaskId:294)
1>      12 mono.android.animation (TaskId:294)
1>      29 mono.android.app (TaskId:294)
1>       2 mono.android.bluetooth (TaskId:294)
1>      20 mono.android.content (TaskId:294)
1>       2 mono.android.database.sqlite (TaskId:294)
1>       6 mono.android.drm (TaskId:294)
1>       6 mono.android.gesture (TaskId:294)
1>       2 mono.android.graphics (TaskId:294)
1>       2 mono.android.graphics.drawable (TaskId:294)
1>       8 mono.android.hardware (TaskId:294)
1>       2 mono.android.hardware.display (TaskId:294)
1>       2 mono.android.hardware.input (TaskId:294)
1>       2 mono.android.inputmethodservice (TaskId:294)
1>       6 mono.android.location (TaskId:294)
1>      60 mono.android.media (TaskId:294)
1>      16 mono.android.media.audiofx (TaskId:294)
1>       2 mono.android.media.effect (TaskId:294)
1>       2 mono.android.media.midi (TaskId:294)
1>       2 mono.android.media.session (TaskId:294)
1>       2 mono.android.media.tv (TaskId:294)
1>       2 mono.android.net (TaskId:294)
1>       6 mono.android.net.nsd (TaskId:294)
1>       2 mono.android.net.sip (TaskId:294)
1>      18 mono.android.net.wifi.p2p (TaskId:294)
1>      10 mono.android.os (TaskId:294)
1>      10 mono.android.preference (TaskId:294)
1>       2 mono.android.renderscript (TaskId:294)
1>       6 mono.android.runtime (TaskId:294)
1>       6 mono.android.sax (TaskId:294)
1>       2 mono.android.speech (TaskId:294)
1>       4 mono.android.speech.tts (TaskId:294)
1>       8 mono.android.support.design.widget (TaskId:294)
1>       4 mono.android.support.v4.app (TaskId:294)
1>       4 mono.android.support.v4.content (TaskId:294)
1>       2 mono.android.support.v4.media.session (TaskId:294)
1>       2 mono.android.support.v4.os (TaskId:294)
1>      18 mono.android.support.v4.view (TaskId:294)
1>       4 mono.android.support.v4.view.accessibility (TaskId:294)
1>      12 mono.android.support.v4.widget (TaskId:294)
1>       6 mono.android.support.v7.app (TaskId:294)
1>      32 mono.android.support.v7.widget (TaskId:294)
1>       2 mono.android.text (TaskId:294)
1>       2 mono.android.transition (TaskId:294)
1>      66 mono.android.view (TaskId:294)
1>       4 mono.android.view.accessibility (TaskId:294)
1>       2 mono.android.view.animation (TaskId:294)
1>       2 mono.android.view.textservice (TaskId:294)
1>       8 mono.android.webkit (TaskId:294)
1>      72 mono.android.widget (TaskId:294)
1>       2 mono.com.google.android.gms.common.api (TaskId:294)
1>       2 mono.com.google.android.gms.common.images (TaskId:294)
1>       2 mono.com.google.android.gms.security (TaskId:294)
1>       6 mono.com.google.android.gms.tasks (TaskId:294)
1>       6 mono.com.joanzapata.pdfview.listener (TaskId:294)
1>       6 mono.com.joanzapata.pdfview.util (TaskId:294)
1>      26 mono.com.skytree.epub (TaskId:294)
1>       2 mono.com.squareup.picasso (TaskId:294)
1>       4 mono.java.lang (TaskId:294)
1>       2 mono.java.util (TaskId:294)
1>       2 mono.javax.xml.transform (TaskId:294)
1>       8 mono.org.vudroid.core.events (TaskId:294)
1>       8 mono.uk.co.senab.photoview (TaskId:294)
1>       2 mono.uk.co.senab.photoview.gestures (TaskId:294)
1>      83 okio (TaskId:294)
1>       2 opentk (TaskId:294)
1>       2 opentk.platform.android (TaskId:294)
1>       2 opentk_1_0 (TaskId:294)
1>       2 opentk_1_0.platform.android (TaskId:294)
1>      65 org.vudroid.core (TaskId:294)
1>       6 org.vudroid.core.events (TaskId:294)
1>       6 org.vudroid.core.models (TaskId:294)
1>       3 org.vudroid.core.multitouch (TaskId:294)
1>       1 org.vudroid.core.utils (TaskId:294)
1>       4 org.vudroid.pdfdroid.codec (TaskId:294)
1>    2455 uk.co.senab.photoview (TaskId:294)
1>      16 uk.co.senab.photoview.gestures (TaskId:294)
1>       1 uk.co.senab.photoview.log (TaskId:294)
1>       4 uk.co.senab.photoview.scrollerproxy (TaskId:294)
1>C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2152,3): error MSB6006: "java.exe" exited with code 2.
1>    DexOutputs:  (TaskId:294)
1>Done executing task "CompileToDalvik" -- FAILED. (TaskId:294)
1>Done building target "_CompileToDalvikWithDx" in project "WebSchoolAndroid.csproj" -- FAILED.: (TargetId:147)

任何人都请帮助我。 提前谢谢。

4 个答案:

答案 0 :(得分:0)

最后,经过48小时的斗争,我得到了答案。我所做的就是将包名称从 com.myexample.droid更改为AndroidMainfeast.Xml文件中的com.myexample.mainapplication <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myexample.mainapplication" android:versionName="1.0" android:installLocation="auto" android:versionCode="9">,这对我来说很有用。祝每个人好运。为了清楚起见,请查看此链接"trouble writing output: Too many field references: 70185; max is 65536. You may try using --multi-dex option." when building Android project。 并阅读此信息

  1. 不需要图书馆项目。将所有内容打包成一个整体结构。
  2. 将项目文件拆分为多个dex文件。

    1违背了软件开发的基本软件原则 - 代码需要开发为可重用的库。

  3. 2是一个很好的长期解决方案,但更复杂。

    解决方案:在更加密切地了解之后,出现了一个合理的中期解决方案。 AndroidManifest.xml文件中清单标记中包名称的重要性在于它被用作标识Android资源的完全限定名称。它与java类本身的包名没有任何关系。

    我按照相同的流程进行了更改并成功构建了既不启用MultiDex也不执行ProGuard。记住我的MaxHeapSize是1G。

答案 1 :(得分:0)

在我更新Google服务包(nuget)后,它对我有用。

答案 2 :(得分:0)

对于我来说,将false从True更改为false可以解决问题

答案 3 :(得分:0)

对我来说,将android.csproj内部的false从True更改为false可以解决问题