I'm trying to build a Xamarin.Android app, but the build always fails with error MSB6006: "java.exe" exited with code 2
. I've tried enabling ProGuard and multi-dex, deleting the bin and obj folders, updating all NuGet packages, switching to debug and release modes, and removing all unused references. The error always points to C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets
on line 1965, but that does not help. I've been struggling with this issue for days and I have no idea what to do next. These are some SO questions that I've seen, but haven't helped:
Asked
Active
Viewed 4,339 times
2

Greg Whatley
- 1,020
- 1
- 13
- 32
-
1I have exactly the same problem – Alvaro Rivoir Jun 12 '17 at 22:40
-
My issue was caused by the wrong JDK being used. VS2019 keeps auto-detecting the 'Eclipse Foundation JDK', when in fact it needed to use JDK 11 located at, "C:\Program Files\Microsoft\jdk-11.0.12.7-hotspot" – Damian Feb 28 '22 at 21:57
4 Answers
3
You can try to enable Multi-Dex in Android project.
- Right click on Android project
- Options
- Android Build
- General
- Check: Enable Multi-Dex
Now Rebuild the project.

tausiq
- 937
- 1
- 13
- 23
0
Issue for me was android-sdk
path containing "space".
Run following command
mklink /J C:\andsdk "C:\Program Files (x86)\Android\android-sdk"
and change the SDK path in Tools > Options > Xamarin > Android Sdk Location
Enable MultiDex also if doesn't work.

Vishnu
- 2,135
- 2
- 30
- 51
0
My guess and it's just a guess is this is related to a poorly constructed keystore or something amiss in Java, like an incorrect path. But I don't know what to do next and in the meantime my project is halted.

Ron
- 2,435
- 3
- 25
- 34
-1
I fixed this problem by creating a new project and copying the old project's code, resources, and packages to the new one.

Greg Whatley
- 1,020
- 1
- 13
- 32