Life as a developer

Obscure issues in Xamarin.Android

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. This can be identified by Too many field references: x; max is 65536. 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.

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 …)

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”

I am using VS Emulator for Android. I got some issues related to that as well, most was easy to fix, but “could not connect to the debugger” was a bit tricky. This post saved my day.

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 clean and rebuild. If that does not help, delete folders under ~/.local/share/Xamarin (OS X) or ~\AppData\Local\Xamarin\ (Windows).

goldnarms

Arnstein Johansen is a .NET Developer with a speciality in web development, but he also dabbles in mobile development and everything new and exciting. Arnstein works for Itema AS, a mid-size consultant agency in Trondheim. Itema has 25 consultants and recently won the prize for Norway's best workplace. He likes to share his knowledge by holding talks for others, either it is clients, colleagues or likeminded developers in user groups. He has hands-on experience from large projects, the latest from Urørt where he leads a team of developers creating a music service used by around 100000 users.

One Comment

  1. Thank you so much for your help regarding the The “CheckDuplicateJavaLibraries” task failed unexpectedly.
    Best regards
    Julian

Leave a reply