Xamarin: error APT0000: Error parsing XML: syntax error

This error had me hunting for two whole days. I couldn’t understand where the files Xamarin was complaining about. They were certainly not mine….

I noticed that when I backgraded to Xamarin.Forms v1.5.1.6471 the problem disappeared. After fiddling around desperately (as you do) a pattern emerged. The trick seemed to be to not reference the support libraries Xamarin.Android.Support.* that had versions > 23.0.1.1.

As soon as they were referenced, the build crashed and I had bad xml in my resourcecache in the obj folder.

obj\Debug\resourcecache\DA97546C26E54413F6BB75B0531999D2 \res\anim\abc_fade_in.xml(2): error APT0000: Error parsing XML: syntax error

Specifically the files were Android source files. E.g. res/anim/abc_fade_in.xml or res/anim/abc_slide_out_top.xml.

How does this work? Well, when you add a nuget package either explicit (as with Xamarin.Forms) or implicit (as its dependencies) they are downloaded to your packages folder in your solution. When you build your solution, these are unpacked and cached in /Users/<username>/AppData/Local/Xamarin folder. One subfolder per reference and version. Like so:

AppData\Local\Xamarin\Android.Support.v7.AppCompat\23.0.1.3\embedded\res

This is were the bad xml came from. As it happended, Xamarin managed to download the full structure of the source files but failed (silently mind you) to download the content of some of them.

This was the content of one of the files (values-land.xml)

badxml

Ah, finally – the error messages really made sense now.

Since these folders only works as a cache, the solution was easy. Delete them.

I deleted the folder at component-level, i.e. AppData\Local\Xamarin\Android.Support.v7.AppCompat. When I did a new build in Visual Studio it downloaded a fresh copy and my build worked.

I of course had to do a clean solution first to get rid of the bad xml in obj\resourcecache.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s