Xamarin Java.exe exited with code 1 (Proguard Issu

2020-02-06 23:52发布

Another day with Xamarin! Can't even build my first Hello World project! Not surprising, huh?

So, fresh new Xamarin.Android blank project. Enabled ProGuard, link to SDK Assemblies Only and went on building the project. And wallah!! There's an error!(Wait, i shouldn't be surprised, right? After all, it's Xamarin). Here's the error :

"java.exe" exited with code 1

Double-clicking the exception opens up Xamarin.Android.Common.Targets file and points to the ProGuard tag which is as follows :

<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)"
/>

So, my best guess was that it might be a ProGuard related issue. So, searched up google and applied all fixes i found so far :

  • Updated Android SDK
  • Set Java heap size to 1G(and even 5G)
  • Enabled Multi-Dex
  • Updated ProGuard
  • Created a new proguard.cfg file in solution(of course set build action to ProGuardConfiguration and added custom lines that are necessary.

But still, same error pointing to the same ProGuard tag. Now before anybody starts bashing me saying i could've messed up the proguard configuratiom file, here's the link to it:

I have read that this is a very common issue in Xamarin. So, i guess, somebody might have come up with a solution that really works!. So, any fixes or ideas on what i might be missing?

2条回答
闹够了就滚
2楼-- · 2020-02-07 00:23

Proguard can be a bit of a pain. The usual symptom is something like

java exited with code 1

Steps that worked for me (I had these notes stored in my solution because it just wasn't obvious). Lifted from this site

  1. Download the latest version of Proguard
  2. Find where your Android SDK is installed (something like /android-sdk/tools/proguard”). To find the sdk go to Tools->Options->Xamarin
  3. Swap out the old version of Proguard, with the new one. To do this rename the current folder to something like “Proguard-pointless” and copy your new one into the tools folder.
  4. Be sure to rename the folder for the new version to just be “proguard”.
  5. Make sure that any configuration files are also copied across into the new Proguard folder. For me this was proguard-android-optimize.txt, proguard-android.txt, and proguard-project.txt.
  6. Add a new file to the root of your Android project called proguard.cfg

    NOTE : Because Xamarin is smart, it saves this new file in UTF-8 with BOM, you will need to change this. Probably best to create the file in notepad, and then include it in your program. This is required because Proguard will not read the file unless it is in UTF-8 encoding.

  7. In VS Right Click on the file and select Properties. For Build Action, select ProguardConfiguration.
  8. Add relevant keep or dontwarn clauses to the file without the quotes (it depends on your warnings) , for example it could be something like this...
    • "-dontwarn com.google.android.gms.**"
    • "-keep class com.google.android.gms.**"
  9. Once you have done those steps, try a build once again.
  10. Hopefully this time it will be more successful. If it is not successful, check your build output and see what warnings and notes Proguard is giving you.

From this stage it is a matter of identifying what modifications you need to make to your custom Proguard file, once that works the build will be successful.

查看更多
爷的心禁止访问
3楼-- · 2020-02-07 00:40
  1. Make sure that the proguard file you added is NOT a Unicode text file (U+FEFF byte order mark (BOM)) as proguard will fail...

  2. Enable diag. level logging for MSBuild and get the full error message.

  3. Proguard is being replaced by Google's R8

If you are using the latest version of Xamarin, refer to this blog post as a start:

Detailed info on the various D8/R8 project configurations can be found in the Xamarin.Android repo here:

查看更多
登录 后发表回答