c# - Xamarin Java.exe 以代码 1 退出(Proguard 问题)

标签 c# android xamarin xamarin.android proguard

又是 Xamarin 的一天!甚至无法构建我的第一个 Hello World项目!不足为奇吧?

所以,新鲜的Xamarin.Android空白项目。已启用 ProGuard , 链接到 仅限 SDK 程序集 并继续 build 该项目。和哇!! 有一个错误!(等等,我不应该感到惊讶,对吧?毕竟,它是 Xamarin)。这是错误:

"java.exe" exited with code 1



双击异常打开Xamarin.Android.Common.Targets文件并指向 ProGuard标签如下:
<Proguard
Condition="'$(AndroidEnableProguard)' == 'True' and '$(_ProguardProjectConfiguration)' != ''"
ProguardJarPath="$(ProguardJarPath)"
AndroidSdkDirectory="$(_AndroidSdkDirectory)"
JavaToolPath="$(JavaToolPath)"
ProguardToolPath="$(ProguardToolPath)"
ToolExe="$(ProguardToolExe)"
UseProguard="$(UseProguard)"
JavaPlatformJarPath="$(JavaPlatformJarPath)"
ClassesOutputDirectory="$(IntermediateOutputPath)android\bin\classes"
AcwMapFile="$(_AcwMapFile)"
ProguardCommonXamarinConfiguration="$(IntermediateOutputPath)proguard\proguard_xamarin.cfg"
ProguardGeneratedReferenceConfiguration="$(_ProguardProjectConfiguration)"
ProguardGeneratedApplicationConfiguration="$(IntermediateOutputPath)proguard\proguard_project_primary.cfg"
ProguardConfigurationFiles="$(ProguardConfigFiles)"
JavaLibrariesToEmbed="@(_JarsToProguard);@(_InstantRunJavaReference)"
ExternalJavaLibraries="@(AndroidExternalJavaLibrary)"
DoNotPackageJavaLibraries="@(_ResolvedDoNotPackageAttributes)"
ProguardJarOutput="$(IntermediateOutputPath)proguard\__proguard_output__.jar"
EnableLogging="$(ProguardEnableLogging)"
DumpOutput="$(IntermediateOutputPath)proguard\dump.txt"
PrintSeedsOutput="$(IntermediateOutputPath)proguard\seeds.txt"
PrintUsageOutput="$(IntermediateOutputPath)proguard\usage.txt"
PrintMappingOutput="$(IntermediateOutputPath)proguard\mapping.txt"
ProguardInputJarFilter="$(_AndroidProguardInputJarFilter)"
/>

所以,我最好的猜测是它可能是 ProGuard 相关问题。所以,搜索了谷歌并应用了我迄今为止发现的所有修复:
  • 更新了 Android SDK
  • 将 Java 堆大小设置为 1G(甚至 5G)
  • 启用多 Dex
  • 更新了 ProGuard
  • 在解决方案中创建了一个新的 proguard.cfg 文件(当然将 build action 设置为 ProGuardConfiguration 并添加了必要的自定义行。

  • 但是,同样的错误指向相同的 ProGuard标签。现在,在有人开始抨击我说我可能弄乱了 proguard 配置文件之前,这是它的链接:
  • ProGuard.cfg
  • Build Output From Visual Studio 2017

  • 我读过这是 Xamarin 中一个非常常见的问题。所以,我猜,有人可能想出了一个解决方案 真的有效! .那么,关于我可能缺少的任何修复或想法?

    最佳答案

  • 确保您添加的 proguard 文件不是 Unicode 文本文件(U+FEFF 字节顺序标记 (BOM)),因为 proguard 将失败...
  • 启用诊断。 MSBuild 的级别日志记录并获取完整的错误消息。
  • Proguard 正在被 Google 的 R8
  • 取代

    如果您使用的是最新版本的 Xamarin,请参阅此博客文章作为开始:
  • Android’s D8 dexer and R8 shrinker

  • 有关各种 D8/R8 项目配置的详细信息,请参见此处的 Xamarin.Android 存储库:
  • This is the D8 and R8 integration specification for Xamarin.Android.
  • 关于c# - Xamarin Java.exe 以代码 1 退出(Proguard 问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55553587/

    相关文章:

    c# - 将特定值从 UWP 添加到数据库

    c# - Linq OrderBy 子列表

    android - 父 Activity 工具栏隐藏在子 fragment 中

    android - 从原始文件夹播放视频

    c# - 使用 SignalR 时的 Azure 服务总线或 Azure Web 应用程序

    C# 读取 XML 元素和文本

    c# - Metro 应用程序中的 List<T>.Find 方法

    android - 再次调用 "onCreateView"- Android

    xamarin - 如何在 Xamarin.Forms 中创建永无止境的后台服务?

    ios - UIWebView 使用 NSUrlProtocol Xamarin.Forms 缓慢加载