Search code examples
androidxamarinnugetteamcitynine-patch

Xamarin 9-Patch in Library Solution & Referenced via TeamCity NuGet


The Configuration

In a library solution is an Android library project (let's call it Core.Droid) that has a 9-patch image as shown in this screen shot of the project

AndroidProject.Resources.drawable-hdpi.textfield_acivated_holo_light.9.png

This solution is built using TeamCity such that the project is a NuGet package.

Another Solution contains an Android project (let's call it DroidApp) and references the NuGet package Core.Droid


The Problem

When DroidApp is built (VS2013) the following compile error is shown:

9-patch image C:\[path to project]\obj\Debug\__library_projects__\Core.Droid\library_project_imports\res\drawable-hdpi\textfield_activated_halo_light.9.png malformed

In order to prove that the problem is somewhere in the NuGet package process... if I make a direct reference to the Core.Droid project by right-clicking References in DroidApp, clicking Add Reference..., and then in the Reference Manager - DroidApp window, on the Browse tab, clicking Browse... and selecting the Core.Droid.dll in the bin\debug location of the Core.Droid project then the DroidApp will compile and run without any compile or runtime errors.


The Question

How do I get the Core.Droid NuGet package to work in the DroidApp when the Core.Droid Android library project contains 9-patch images?

Note: Normal images work just fine, it's only 9-patch images that cause this problem.


Current Workaround

If we put the 9-patch images in the DroidApp then everything is hunky-dory. However this makes it impossible to share images across multiple apps from a common library project, consequently we have the same images in multiple projects. This is bad.

Additional Information

I see this in the diagnostic build log:

2>AAPT : error : 9-patch image C:\Workspace\DroidApp\obj\Debug\__library_projects__\Core.Droid\library_project_imports\res\drawable-mdpi\textfield_activated_holo_light.9.png malformed.
2>         No marked region found along edge. (TaskId:145)
2>         Found along top edge. (TaskId:145)

However I think this is a symptom of the problem, not necessarily the cause because the image that is included in the project is not malformed… in fact, if I make a direct reference to the project (Core.Droid) instead of using the NuGet package… it works. However, if I browse to the path in the error, then the image is indeed malformed (the 9-patch borders are removed). So the question is… how does this happen? Why when it’s a NuGet project does it strip the borders out? I do know that if I grab the image from an .apk then the 9-patch borders are in fact removed… so perhaps somewhere in the build process when building the NuGet package this happens… whereas when the project is included as a direct reference that step does not happen… is there a way to prevent that step from happening in a NuGet build?

Additional Information II

If I build the NuGet package on my local machine and use that NuGet package then it works. It's only with the TeamCity's NuGet package that the 9patch doesn't work.


Solution

  • Just to clarify, the solution was to update past Xamarin.Android 4.18 as 4.18.1 seemed to have a fix for this:

    https://bugzilla.xamarin.com/show_bug.cgi?id=23835

    http://developer.xamarin.com/releases/android/xamarin.android_4/xamarin.android_4.18/#Xamarin.Android_4.18.1

    Which resolved https://bugzilla.xamarin.com/show_bug.cgi?id=23823 as well!