I have been developing apps with Xamarin for a while now and as a .Net developer, I prefer Visual Studio and C# over Android Studio and Java. Xamarin helps me out a lot, but even they can’t fix all of those pesky Android issues.
The error messages returned by Visual Studio or Xamarin Studio are not always clear, but I recommend that you select Detailed or Diagnostic log output, so you might get a better clue.
This is a small collection of some of issues that I have encountered, and what I did to fix them.
“javac failed with code 2.”
There are several issues that might cause this error, but for me it was that I surpassed the 64K method limit. To read more about it, check out this post. This can be identified by
Too many field references: x; max is 65536. First you can see if you can lower the number of references, removing Google Play can reduce it by 20k. If that is not an option, this can be solved by right clicking the android project, options, and enable multi-dex. You should also do some changes to your Application file so that this works on devices that are not on Lollipop yet.
See here for implementation.
Sadly enabling Multi-Dex caused several other issues to appear.
Expecting class path separator ‘;’ before ‘\Android\android-sdk\build-tools\23.0.1\lib\shrinkedAndroid.jar’ in argument number 8
You can get this issue if your Android SDK are located in a path with space (e.g. Program files). I fixed this by moving both my Android SDK and JDK to a path without space,
The “CheckDuplicateJavaLibraries” task failed unexpectedly.
For me, this error came since I did not have the correct support libraries downloaded by the SDK Manager. I needed to check the box for obsolete packages, and download the support libraries available.
The file “obj\Debug\android\bin\packaged_resources” does not exist.
This is usually caused by a resource with an invalid filename. A dash (-) is a common culprit. You can open up PowerShell and run this command to show all files with a dash
Get-ChildItem -Include *-* -Recurse. Then it should be easy to just replace all dashes with an underscore.
“aapt.exe” exited with code -1073741819
See fix above. If that does not work, you most likely are on an unstable Xamarin channel (Alpha or Beta) or have downloaded SDK’s in preview. Try to revert back to a stable channel and SDK’s. You can find channel under Tools -> Options -> Xamarin -> Other in Visual Studio or Check for Updates … Preview SDK’s can be managed from the Android SDK manager.
Compilation error (Unzipping failed.Please download …)
- Delete everything from AppData\Local\Xamarin\zips
- Rebuild the solution
Invalid resource directory name “res assets” – aapt.exe
Make sure all your resources placed under assets have the correct build action. It should be “AndroidAsset”.
“could not connect to the debugger”
Attribute “xxx” has already been defined
This is caused by two or more packages that has defined the same attributes. First try to delete “bin” and “obj” folders, run
rebuild. If that does not help, delete folders under ~/.local/share/Xamarin (OS X) or ~\AppData\Local\Xamarin\ (Windows).
The “GetAndroidPackageName” task failed unexpectedly
It is most probably due to a corrupt AndroidManifest.xml file, you can find it under the Properties folder.
Unsupported class version number [52.0]
I got the error:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Tool exited with code: 10. Output: Error: Can't read [/Library/Frameworks/Xamarin.Android.framework/Versions/7.0.2-37/lib/xbuild-frameworks/MonoAndroid/v7.0/mono.android.jar] (Can't process class [android/app/ActivityTracker.class] (Unsupported class version number [52.0] (maximum 51.0, Java 1.7)))
The application could not be started
Make sure that the application has been installed to the target device and has a launchable activity (set with the attribute:
MainLauncher = true).
Additionally, check Build->Configuration Manager to ensure this project is set to Deploy for this configuration.
If the problem persist, try this as a last option:
Go to Android adb command prompt (Tools -> Android -> Android Adb command prompt and run:
Then Clean, Build and Deploy
Duplicate class definitions
If you get something on the lines of this:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Tool exited with code: 10. Output: Note: there were 103 duplicate class definitions. It is most likely because of proguard, see link
“java.exe” exited with code 1
Yet an error message with no clear solution:
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2118,3): error MSB6006: "java.exe" exited with code 1.
What worked for me: Update proguard (see above), install Java JDK on a path without spaces and update your SDK’s.
error MSB6006: “java.exe” exited with code 2
I ran into this issue after a Google Play Services update. Go through all the libraries and remove the ones the ones that you don’t need.
Could not connect to the debugger
See this post for the solution that fixed it for me.
This means that you have not built the app for the correct processor architecture. Open up Properties for your Android project, go to Android Options, Advanced and check “Supported architectures” to make sure that they are set up right (x86 for emulators, arm for device). If this still does not help, this forum thread is worth checking out.
Couldn’t connect to logcat, GetProcessId returned: 0
Check processor architectures, I had to enable armeabi and armeabi-v7a. If that does nothing, try deactivating “Fast Deployment” in project settings and/or deselecting ‘Use Shared Runtime’ in Project Properties -> Android Options -> Packaging properties. Finally try closing Emulator, Cleaning solution then Running solution.
Could not resolve field token 0x040000c2
This can be related to shared runtime.
Couldn’t connect to logcat, GetProcessId returned: 0 xamarin
There can be several solutions for this:
- Deactivating “Fast Deployment” in project settings.
- Application properties Android Manifest ->Required Permission ->Enable ACCESS_COARSE_LOCATION and INTERNET
- Android Options -> Supported Architecture -> Enable armeabi and armeabi-v7a
- Deselecting ‘Use Shared Runtime’ in Project Properties -> Android Options -> Packaging properties
- Selecting Microsoft as Debugger in Debug mode
- running adb logcat -c
worker unparking, timeout? no interrupted? no
Set environment variable MONO_LOG_LEVEL=message, by
adb shell setprop debug.mono.env "MONO_LOG_LEVEL=info" or by adding a file to your project with the text `MONO_LOG_LEVEL=info` (I set my filename to “envar.txt”) and set build action to “AndroidEnviorment”.
The “Xamarin.Forms.Build.Tasks.GetTasksAbi” task could not be loaded from the assembly
Unload your project and edit .csproj file, check that you don’t have multiple references to Xamarin.Forms packages.