read

I am doing a lot of development using Xamarin for Android and while most of the time it works really well, there are a few circumstances where it acts a little weirdly.

The first is when naming resources. The Xamarin documentation states the following in a resource on their website:

[blockquote source=”Xamarin”]Also, it’s important to note that while Android only supports lowercase filenames for resource items, Xamarin.Android is a bit more forgiving; it will support both uppercase and lowercase filenames.[/blockquote]

While this is true for most items it doesn’t work across the board. When naming drawable resources likes shapes or bitmaps and referring to them from a style I cannot use uppercase characters. I am from a C# background so I find it hard to let go of Pascal case for naming my files. If I name a file TextRectangle.xml I don’t seem to be able to reference it from a style like so:

[syntax type=”html|php|js|css”]

[/syntax]

If instead I rename the file to text_rectangle.xml I’m all good in the hood. This messes with my OCD a little as everything is Pascal case except for a handful of drawable resources sprinkled through the solution.

The next weird issue I have encountered is a situation that can occur with the Resource.Designer.cs file. This file is automatically generated to give static access to all of the layout elements available. This is described as the following:

[blockquote source=”Xamarin”]Resource.designer.cs – This file is automatically generated and maintained by Xamarin.Android and holds the unique ID’s assigned to each resource. This is very similar and identical in purpose to the R.java file that an Android application written in Java would have. It is automatically created by the Xamarin.Android tools and will be regenerated from time to time.[/blockquote]

If this ever doesn’t rebuild correctly I read that you can just delete it and it will be rebuilt on the next project compilation. This is true but when you add it back to the project after it is rebuilt, something strange will happen. The next compilation will fail with an obscure error in aapt.exe with the description, “Invalid resource directory name: “resource.designer.cs”. I found a few references to this error but couldn’t figure out exactly what had gone wrong. After an hour or two of tearing my hair out I compared the project file to a previous version and realised that the build action had been set to AndroidResource when I re-added it the file. This file’s build action should be set to Compile and when I specified this everything returned to normal.

droid error

I understand that these are a couple of pretty specific issues but if they help someone else then it will have been time well spent writing this up…

Enjoy…

 

 

slamb2k


Published on

Show Comments
  1. Ghenadie says:

    Thank you very much!!!

  2. Mr Havre says:

    Just to add, I just had another similar problem. Two xmls in the drawable folder didn’t want to get added to Resource.Designer. For some reason these files did not get the Build Action “AndroidResource” but were set incorrectly to Bundle-something.

    Setting these resources to AndroidResource and then rebuilding solved my issues.


Leave a Reply

Your email address will not be published. Required fields are marked *

Kym Phillpotts

I write about Xamarin Forms, mobile development or whatever else I might be concentrating on.

Back to Home