Xamarin Java.Exe Exited with Code 1 (Proguard Issue)

Xamarin android project java.exe exited with code 1

I've found the problem. The project was developed on android 11 and could build without a problem, the problem began when the target framework version was changed android 12, first the build error was:

'Xamarin.Android.Support.v4' is using '[assembly:
Java.Interop.JavaLibraryReferenceAttribute]' , which is no longer
supported. Use a newer version of this NuGet package or notify the
library author.

So we made sure that all nuget packages could run on android 12 than the build error changed to:

is also present at androidmanifest.xml:22:18-91 value (android.support.v4.app.corecomponentfactory)

this is was just one of the several java errors and all the errors were related to android.support.v4.app library. So during my first research I've found from the in xamarin community that some were able to solve their problem by adding the code :

tools:node="replace"

to their AndroidManifest.xml file under the <application> tag. So I did just that to see the results and the error than changed to:

"java.exe" exited with code 1

after going back to the first "android.support.v4.app" error and doing some more research about it online I've found that android studio users could solve these type of errors by setting the "useAndroidX = true" in their build.gradle file. Not having a build.gradle file in my project I've just decided delete the code I previously added to my AndroidManifest.xml and to add the "Xamarin.AndroidX.Core" Nuget package to my android project, after doing so the error changed to:

Could not find Jetbrains.Annotations

So after also adding the "Xamarin.Jetbrains.Annotations" nuget package to my project ,it now builds without an error.

Xamarin Java.exe exited with code 1 (Proguard Issue)

  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:

  • Android’s D8 dexer and R8 shrinker

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

  • This is the D8 and R8 integration specification for Xamarin.Android.

java.exe exited with code 1 Xamarin C#

Clear your obj and bin folder for both projects. (PCL and Android).

If you're using a custom proguard tool, verify the file encoding is in utf or Ascii.

Error java.exe exited with code 1 Xamarin Firbase Messaging

Apparently it was due to the update I made of visual studio because the android SDK was also updated, the solution was to edit [Services] to [Services(Exported = true)] for android +31, leaving the final code like this.

[Service(Exported = true)]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]

public class MyFirebaseMessagingService : FirebaseMessagingService
{
readonly AndroidNotificationManager _androidNotification = new AndroidNotificationManager();
public override void OnMessageReceived(RemoteMessage message)
{
var mensajeData = message.Data;

string title= mensajeData["notiTitle"];
string bodymessage= mensajeData["notiBody"];

_androidNotification.CreateLocalNotification(title, bodymessage);
}

public override void OnNewToken(string token)
{
base.OnNewToken(token);
Preferences.Set("TokenFirebase", token);
}
}

After adding that, everything compiled correctly

font answer

ProGuard: java.exe exited with code 1 after adding ModernHTTPClient

It sounds like all you need to do is add a proguard.cfg file to your project with build action set to ProguardConfiguration to remove any warnings and keep any necessary classes for example:

# General Android
-dontwarn org.apache.http.**
-dontwarn android.net.http.AndroidHttpClient

# Android Support Library
-keep class android.support.multidex.MultiDexApplication
-keep class android.support.v4.**
-keep class android.support.v7.** {
public *;
}

# Google Play Billing
-keep class com.android.vending.billing.**

# Google Play Services
-dontwarn com.google.android.gms.internal.*
-keep class * extends java.util.ListResourceBundle {
protected java.lang.Object[][] getContents();
}

Error java.exe exited with code 1 - Xamarin

After a long research I have found solutions for this issue.

First download latest Proguard file from here unzip and copy to sdk path C:\Program Files (x86)\Android\android-sdk\tools, this path could be different in your case.

There must be already one proguard folder, rename that to proguard.old. Now from proguard.old folder copy and paste proguard-android, proguard-android-optimize, proguard-project files to newly created proguard folder.

After that need to follow below steps

  • Create txt file somewhere in your PC and change extension to .cfg.
  • Change proguard.cfg file Encoding using Notepad++ to UTF-8 without BOM and Save As somewhere.
  • Now add this new proguard.cfg to your android project level.
  • Change proguard.cfg file build action to ProguardConfiguration
  • Clean your project.

If you are getting warnings with prefix progurd like this

PROGUARD : warning : com.appdynamics.eumagent.runtime.private

Now you need to add this package to your custom proguard.cfg file like

-dontwarn com.appdynamics.eumagent.runtime.**

With -dontwarn do not use keyword class. Here ** takes all child classes of given package.

If you are getting exception then you need to find out which library causing issue and add that in proguard.cfg file with -keep keyword

-keep public class android.support.v7.widget.** { *; } 

If you see your full log carefully progaurd gives all warnings to make us easy to find out issue.

Xamarin.Android.D8.Target - java.exe exited with code 1 on creating proguard configuration file

Problem rises When you create/save proguard file.

Xamarin Uses two type of UTF-8 encoding.

  1. UTF-8 (Only)
  2. UTF-8 with BOM (default by xamarin during new file creation)

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.



Related Topics



Leave a reply



Submit