41

I put together a fairly simple Mono for Android application that does nothing more than play an "AndroidResource" MP3 in a background service (copied from Greg Shackles latest Visual Studio Magazine article on Background Services in MfA). I put the code together, with my own custom MP3 file, and tried to build it, only to get this lovely error.

"aapt.exe" exited with code 1

That is the only info in the error list and build output log.

patridge
  • 26,385
  • 18
  • 89
  • 135

9 Answers9

74

Step 1: get more info

If you run across this error, hopefully, you will also run across a post from Jonathan Pryor replying to someone else with the same problem. The suggestion is to turn on more verbose logging from MSBuild to see if you get something useful out of those messages.

In the Visual Studio Options dialog, go to "Projects and Solutions" then "Build and Run". Switch the "MSBuild project build output verbosity" from "Minimal" to "Normal" and build your project again. After doing so, I got this message which was far more helpful. Apparently, resources cannot include anything but letters, numbers, periods, and underscores ([a-z0-9_.]).

MSBuild normal verbosity logging

Solution

Rename file within the required restrictions and build again.

While this error message may come up for far more situations than filename restriction issues, a filename change fixed this particular issue completely.

Community
  • 1
  • 1
patridge
  • 26,385
  • 18
  • 89
  • 135
  • You can often get better error messages for that kind of thing by increasing the build verbosity: http://docs.xamarin.com/android/troubleshooting#monodroid.exe_or_aresgen.exe_exited_with_code_1 – Greg Shackles Jul 11 '12 at 20:57
  • 21
    +1 for **resources cannot include anything but letters, numbers, periods, and underscores ([a-z0-9_.])**. For me, it turned out that I created a file out of this criteria in my Layout. – PCoder Jan 06 '13 at 19:19
  • 1
    I just had a space in the name of my drawable.... I removed it and bob's your uncle – Aiden Strydom Jun 25 '13 at 23:04
  • Wow, the build output while doing Xamarin development was always horribly unhelpful. This tip of yours is going to make such a big difference for me. – Leon Cullens Mar 02 '16 at 18:47
30

Similar solution for me, I needed to remove the dashes ('-') from my PNG filenames in the resources folder

Joel
  • 516
  • 4
  • 7
14

In Mono.Android projects this error occurres when a Resources/Layout axml file has whitespaces in the name, eg. "Copy of xxxx.xaml"

Hersker
  • 547
  • 5
  • 11
8

In Mono.Android projects this error can happen when a Resources/Drawable file name has - in the name, eg: "File-Name.png try with underscore: "File_Name.png"

StefanoM5
  • 1,327
  • 1
  • 24
  • 34
4

Yes, Remember to not have:

  1. Resources, Images, Assets, Layout axml beginning with mumbers
  2. To check your file names with spaces. (I had this issue. One of my layouts had an ending space just before the extension ".axml")
  3. To check if any of your images, resources, files, layouts or others have any hyphen (-). They are not supposed to be there.
  • I had a hyphen in an image name was causing this error. – vikingben Dec 31 '16 at 00:03
  • Your answer was usefull. I had one file with a hyphen. I renamed it, but the error has disappeared after I unload the project and then reload it again. – Stefan Babos Jan 27 '17 at 18:03
  • You are right! I copied an XML file in the project as a backup which renamed it `my-xml-file - Copy.xml` which caused both this error and the `Resources.Designer.cs` not updating. – SharpC Apr 21 '17 at 22:39
3

For me it was a problem with a resource name. One of my pictures was from MonoTouch and as such its filename included an '@2x' in the filename. After removing this aapt.exe no longer complained and the solution built.

Dylan
  • 1,919
  • 3
  • 27
  • 51
2

Follow the steps below to identify the problem:

1 - In Visual Studio: Tools> Options> Projects and solutions> Build and Run.

1.1 - In the dropdown: MSBuild project build output verbosity:> Diagnostic.

1.2 - Close the dialog box.

2 - View> Output (Ctrl + W, O).

3 - Run the build or rebuild.

In the output find this line:

C: \ Program Files (x86) \ MSBuild \ Xamarin \ Android \ Xamarin.Android.Common.targets (1665.3): error MSB6006" aapt.exe "exited with code 1

What is just above this error is what caused the error.

Tiago S
  • 1,299
  • 23
  • 23
1

Check your images/png(s) on Drawable folder. It gave me an error because of a png image, once it is excluded from project. Works fine...

Ruwan Jayalath
  • 361
  • 5
  • 10
0

I resolved it by removing portable library that contains the business logic from the android and then rebuild it separately. After rebuilding, clean your android project and add reference again to your portable class library. Finally build the android project

Victor
  • 11
  • 1
  • 3