Error MSB6006: "java.exe" exited with code 1 when ProGuard enabled - xamarin

I try to resolve this issue last few days, still without success.
If I build release version without proguard then everything is OK.
I read many topics about possible problems but nothing help in my case.
So far I did as follow:
Java max heap size - 1G
Use "mklink" - mklink /j C:\android-sdk “C:\Program Files (x86)\Android\android-sdk”
Created own proguard.cfg with content:
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(); }
Manually update ProGuard to latest version.
And the result is 0 warnings and 1 error.
ERROR:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1929,3):
error MSB6006: "java.exe" exited with code 1.
What else can I do?
Please help.
Update.
I created brand new app "Xamarin Hello World" and there "ProGuard" works. So it must be something wrong with my app not a system.
But visual studio doesn't show me any other error apart that Java code 1. So how to track where is a problem?
UPDATE
The problem was in my "proguard.cfg" file. I copy content from other source and one line there should be comment but it wasn't. So this problem gone. But now some warnings come out:
2>PROGUARD : warning : can't write resource [META-INF/MANIFEST.MF](Duplicate zip entry [classes.jar:META-INF/MANIFEST.MF])
2>Copying resources from program jar [G:\ApkiC-Sharp\GNote\GNote\GNote.Android\obj\Release\__library_projects__\Xamarin.GooglePlayServices.Basement\library_project_imports\classes.jar](TaskId:345)
2>PROGUARD : warning : can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [classes.jar:META-INF/MANIFEST.MF])
2>Copying resources from program jar [G:\ApkiC-Sharp\GNote\GNote\GNote.Android\obj\Release\__library_projects__\Xamarin.GooglePlayServices.Maps\library_project_imports\classes.jar] (TaskId:345)
2>PROGUARD : warning : can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [classes.jar:META-INF/MANIFEST.MF])
2>Copying resources from program jar [G:\ApkiC-Sharp\GNote\GNote\GNote.Android\obj\Release\__library_projects__\Xamarin.GooglePlayServices.Tasks\library_project_imports\classes.jar] (TaskId:345)
2>PROGUARD : warning : can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [classes.jar:META-INF/MANIFEST.MF])
What dose it mean? Is it something to worried about?
How to check if "ProGuard" works fine?

I was also facing the same issue on my Windows 10 x64 and visual studio 2015. I have set the JDK path to JDK 1.8 under android settings in Visual studio tools ->options ->xamarin ->java development kit location. it was pointing to "C:\Program Files (x86)\Java\jdk1.7.0_55" and I made it to "C:\Program Files\Java\jdk1.8.0_31", and issue has been fixed.

Try enabling the Multi-Dex compilation option.

Related

Xamarin Forms c# - java exited with code 1 in VS Studio for Windows

I am trying to compile an android app with XF. I am getting the infamous java.exe exited with code 1 error message. I have enabled proguard.
I have gotten the error just from enabling proguard.
The error only seems to happen in VS for Windows. I got a different error in VSMac, but don't have that right here in front of me.
Updating proguard from it's home on sourceforge doesn't seem to do anything for me.
I have put a new proguard.cfg file in my project and have set the build property to be a proguard configuration file.
I don't know what to do here. I'm looking for any suggestions.
TIA.
Update 1:
I didn't add the build output because I couldn't find a good exception in it. I just have the following that I can find in the build output.
I wish I could find the error easily. I had turned on the build output. the only exception i can find is listed below. I checked the targets file and the line reference is for the Proguard section.
1> at proguard.Initializer.execute(Initializer.java:485)
1> at proguard.ProGuard.initialize(ProGuard.java:271)
1> at proguard.ProGuard.execute(ProGuard.java:113)
1> at proguard.ProGuard.main(ProGuard.java:572)
1> Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2550,3):
Link to build output: https://www.dropbox.com/s/jl1o2hf7aeji243/BuildOutput.zip?dl=0

Xamarin run error

Severity Code Description Project File Line Suppression State
Error The "Xamarin.Android.Tasks.GetApiLevelFromFramework" task could not be loaded from the assembly C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Build.Tasks.dll. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. xamarin_installed_trial
I get this error when I want to run an android program using xamarin.
Android sdk is properly installedhere is the error
Can you check the target platforms are installed correctly. In Visual Studio ->Android SDK MANAGER -> Platforms
You can check
here

xamarin nuget packages not being found in references

I am having a publishing a release build of my xamarin android app. I recently implemented firebase messenging along with the associated google play services and have all the latest nuget packages installed. However, I still have this showing in my visual studio references -
I was dealing with the proguard issue, java.exe exited with error code 1 and added a proguard file with the following lines -
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-keep class com.google.firebase.** { *; }
-dontwarn com.google.firebase.**
This allowed the app to build but not it just hangs on the splash screen and doesn't goes dark.
Before I got this far I posted here while I was looking for ways to fix my proguard issue. Everything is peachy in a debug release mode but this release build is leaving me without many clues.

Additional Manifest: Warning 81010002

Pasted the following into a exe.manifest file for a VS10 Win32 project from code found here:
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<ws2:longPathAware>true</ws2:longPathAware>
</windowsSettings>
Building generated the linker warning:
warning 81010002: Unrecognized Element "longPathAware" in namespace "http://schemas.microsoft.com/SMI/2016/WindowsSettings".
Understandable, based on the age of the bundled mt.exe as explained in this similar issue.
Question is, will this in any way affect the long path awareness of the application on a platform where the attribute is known?
Downloaded the 2.4 Gb W10 SDK, thanks to Sera's suggestion, and copied the 1 mb file mt.exe over to Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin. Warning not generated with the new mt. (Minor issues with the Environment variables set for the 7.1 SDK in Program Files\Microsoft SDKs\Windows\v7.1\Bin added in some extra flavour and texture to the operation)
Another way is to disable manifest generation in the projects linker options and manually create an external manifest. It must be named like "YourApplication.exe.manifest" and be located next to "YourApplication.exe".
I had to copy the manifest via post-build event as VS always deleted the manifest when doing a clean build.

Is there any way to set the ANDROID_NDK_HOME environment variable from within Visual Studio in the project/solution properties?

I'm setting up build and release process for a project that does some Windows and Android development through Visual Studio 2013 (though some projects still have to have 2012 configs). I'd like for the developers to be able to stay within Visual Studio and not have to jump out to System Properties to change their environment variables in order to test another version of the NDK/SDK.
In the property sheets there's a setting that allows you to define a User Macro and expose it as an environment variable. I've followed the instructions from here (Visual Studio Property Pages Environment Variables) however it doesn't appear to be working (at least not for doing Android stuff).
We tried setting the User Macro in the property sheet for the project as well as "Microsoft.cpp.Android.User" but still get the same error when building:
1>------ Build started: Project: libstuff, Configuration: Release Android ------
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Platforms\Android\Microsoft.Cpp.Android.Targets(570,5): error : Could not find the Android NDK, check that your ANDROID_NDK_ROOT path is correct!
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Platforms\Android\Microsoft.Cpp.Android.Targets(570,5): error : It's currently: '<unset>'
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Platforms\Android\Microsoft.Cpp.Android.Targets(570,5): error : The NDK can be downloaded at this URL:
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Platforms\Android\Microsoft.Cpp.Android.Targets(570,5): error : http://developer.android.com/sdk/ndk/index.html
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
We also tried a pre build event where we set the environment variable from the command line via a "set" with no luck.
Any thoughts on why this might not be working? Is the build order different when doing Android stuff that would cause the environment variables to be set and exposed after the Microsoft.Cpp.Android.Targets is called?
UPDATE *
A small update on this.
We've been able to narrow this down to an issue with MSBuild and how it loads properties.
If you don't want to set the ANDROID_NDK_ROOT and ANDROID_SDK_ROOT you can create a user macro to set those values.
Those are:
$(AndroidNdkDir) and $(AndroidsdkDir)
When MSBuild tries to execute any android build targets it loads two files.
The first is: C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Platforms\Android\vs-android.EnvVars.props
That is where AndroidNdkDir, AndroidSdkDir, and other android properties are set.
The second file depends on the android platform you're on. For example this is the file it's loading for us: C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Platforms\Android\PlatformToolsets\arm-linux-androideabi-4.8
In that file all the Gcc properties are set.
For some reason the AndroidNdkDir property that was set in the first file is not set. I don't see any settings in the Import tag in MSBuild that controls how/if other properties are inherited. Could this be some order of operation thing?
After doing some more research is seems like the answer to this is that it cannot currently be done. I found this bullet point on the VS-Android plugin TODO list (https://code.google.com/p/vs-android/wiki/TODO_List)
Ability to override environment variables for SDK/NDK/Ant/JDK on a
per-project basis in property sheets.

Resources