error MSB6006: “java.exe” exited with code 1. – Xamarin.Android – How to solve ?

When I was trying to build an Xamarin Android app with Release configuration in Visual Studio 2017, I got an error saying..

error MSB6006: “java.exe” exited with code 1.

Then I looked for how to solve the error and I found that the issue happen because of Proguard is enabled.

1

Image 1 : Android options for release configuration

Then I found 2 solutions to solve the issue.

  1. Set Java Max Heap Size in Android options.
  2. Change format of Java Max Heap Size in Android options.(Use M/G instead of MB/GB)
  3. Add a  custom Proguard configuration file.

I tried first 2 options but, it didn’t solve the issue.

2

Image 2 : Change max heap size manually (option 1 and 2)

Final Solution.

The issue solved when I add a Proguard configuration file manually.

Steps to add a Proguard configuration file manually.

    1. Go to Android project
    2. Create new file call proguard.cfg
    3. Right Click on proguard.cfg file and go to properties.
    4. Change build action to Proguard Configuration.
    5. Open the file and add below code..
    6. Save and Re-Build the Android Project..
3

Image 3 : Change build action of proguard.cfg

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**

 

4

Image 4 : code in proguard.cfg

 

Thanks !

 

Reference

https://forums.xamarin.com/discussion/9305/java-exe-exited-with-code-1-xamarin-android-common-targets

https://stackoverflow.com/questions/38147828/java-exe-exited-with-code-1-proguard-issue

How to Fix Error “C:\Program Files (Access is Denied)” When Proguard has Enabled while Build a Android app

Why ?

When I was trying to build one of my android apps in “Release” mode to deploy, I got and Error that  “C:\Program Files (Access is Denied)” and the File was “PROGUARD”.

2-errror

Then I looked for a solution to avoid the error.

What is Proguard ?

The Reason For The Error

In the Android project, I have set the Proguard Enabled before I build the app.

The reason for the error is there is a space in the path to the PROGUARD. Proguard is in the Android folder in Program Files (x86) and there is a spaces between “Program Files (x86)”.

C:\Program Files (x86)\Android\android-sdk\tools\proguard

0-program-file-spaces

So PROGUARD may unable to find the path..

So How to Fix This ?

What we have to do is Place the android-sdk folder to a path without spaces..

To do that I created a symbolic Link(sym-link) ..

Here are steps to create a symbolic link..

1 .First we have to download and Install the  Link Shell Extension.

To Download the Link Shell Extension , Click Here .. 

2. After Installed the Extension then we are ready to create the sym-link.

How To Create a Symbolic Link, Click Here…

Here are steps How I created according to my Folder structure..

First I create a Folder in C: drive outside of Program Files x86 which is “AndroidSysLink”. So we have to Link the Android-SDK path to this folder.

First Go to Program Files x86 and Right Click on Android Folder and we can see a new context menu “Pick Link Source”. Then Click it..

1-pick

Then Go back and Select “AndroidSysLink” Folder -> Right Click . Then We can see a new context menu “Drop As” . When we click on it and we will see few options in another context menu. Then Select “Junction”. And then The link will be created.

2-drop-symbolic-link

3. Then We have to change the Android SDK path in Visual Studio.

So go to Tools -> Options -> Xamarin and Click the “change” button inside of the Android SDK location…

Then we can see a dialogue to select the sdk path..

3-existing-sdk-path

4. Go to the Linked folder and copy the path in it..

4-select-new-path

5. Paste the Path in the sdk-path selection dialogue box.

5-new-sdk-path

Then Click OK…

6. Now The Path has changed an Click OK to conform the new SDK path..

6-new-sdk-path

7. Now we are ready to release the app. But before Build the app recheck the configuration in properties.

First Verify Target Android versions..

0-selectandroid-versions

Make Sure the Confutation has set to “Release” and Proguard is Enabled..

1-enable-proguard

8. Then Build The app in Release Mode..

The app will build successfully..

3-build-success

9. Now we are ready to Archive the Android App.

Right Click on the Android project and click “Archive“…

4-archieve

We can see Archiving Progress…

5-archieving

We can see a Settings I con with a Green icon when the app has archived successfully and in the bottom of the dialogue we can see build information.

6-archieved-successfully

Click the “Open” folder and the created .apk file will see in that folder.

7-open-the-path

References…

https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/publishing_an_application/part_1_-_preparing_an_application_for_release/

https://developer.xamarin.com/guides/android/application_fundamentals/cpu_architectures/

https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/proguard/

https://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux/

http://schinagl.priv.at/nt/hardlinkshellext/linkshellextension.html

https://forums.xamarin.com/discussion/45210/enable-proguard-error-c-program-files-access-is-denied

Thanks !