Search code examples
androidvisual-studioxamarinassets

Why are Android Asset files in Visual Studio (Xamarin) not allowed to have accents?


I have a Visual Studio (Xamarin, Android) project with a file which has an accent character in the name:

 diário.png

This file is in the Assets folder, and marked as an Android Asset.

enter image description here

Unfortunately when I build the project, I get a compile error:

C:\Users\vchel\Documents\FlatRedBallProjects\AndroidSpecialCharacter\AndroidSpecialCharacter\obj\Debug\assets\content\gumproject\dißrio.png : error : Invalid filename. Unable to add.

Notice that the file is diário.png in my project, but the error references it as dißrio.png.

If I rename the file to diario.png (no accent above the letter a) the project builds fine.

I know I could work around this by not using accent characters in my file but this seems like a strange restriction. Is this a known issue? Is there another way to solve this other than avoiding using accents in file names?


Solution

  • Asset naming restrictions are bound all the way back to Android API 1, the related build tools and .apk packaging (and has nothing to due with the Xamarin framework).

    • Valid characters for naming resources are [a-z, _, 0–9]

      • Lowercase characters, numbers, and underscore
    • Use an underscore (_) as a multi-name separator between "words" in your assets

      • Spaces hyphens, and periods are not allowed
    • The first letter can be either _ or a small case character

      • Numbers are not allowed as the first character

    Note: There used to be notes on these restrictions on the Android Developer site, but I can no longer find them as they stripped out most docs for the build tools