TL;DR

Also available in TL;SO (too long; Stack Overflow) flavor.

Getting this error: "aapt.exe" exited with code 1?

Do you have any files in your Mono for Android solution that are being packaged together with the app (e.g., “AndroidResource” build action)?

If so, make sure they don’t have anything but letters, numbers, periods, and underscores ([a-z0-9_.]) in their names.

Details

I am still getting my feet wet with Mono for Android (MfA) development. One of my first projects was a flashlight app for my Galaxy Nexus that introduced me to a couple Android/MfA development quirks. One concept in app development that I would like to explore is long-running tasks. How do I keep something going after the user has switched off to something else?

Greg Shackles has a new Visual Studio Magazine article on Background Services in MfA on just that topic. He creates a background service for playing an MP3 file using a standard Android service.

In his sample project, he sets up the service to play some Creative Commons Nine Inch Nails music.

I happen to have a good collection of my own Nine Inch Nails music. As I put the code together in my own project, I grabbed one such MP3 file, named “02 1,000,000.mp3”, and added it with the “AndroidResource” Build Action. Unfortunately, hitting Ctrl+Shift+B resulted in a lovely error: "aapt.exe" exited with code 1.

If you go to the Visual Studio output window, you don’t find much else of value.

Fortunately, you can get more verbose output from MSBuild if you ask for it. In the Visual Studio Options, go to “Projects and Solutions” then “Build and Run”. Switch the “MSBuild project build output verbosity” from “Minimal” to “Normal”. After I built the project again, I got a little clearer message: res\raw\02 1,000,000.mp3: Invalid file name: must contain only [a-z0-9_.].

A quick name change to something within the [a-z0-9_.] range and the project built beautifully. While this new sample project is just a horrible version of the baked-in music application, that definitely isn’t the point. It is definitely nice to have some code written about a concept before you find yourself needing it the first time.