"aapt.exe" exited with code 1 when building Mono for Android project

20,445

Solution 1

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.

Solution 2

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

Solution 3

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

Solution 4

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"

Solution 5

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.
Share:
20,445
patridge
Author by

patridge

Currently developing internal tooling and processes at Microsoft's Developer Relations, helping scale production and maintenance of educational and reference content. Former mobile and web app developer and Xamarin MVP. Previous projects: Microsoft Learn Xamarin and App Center content Xamarin University (retired) Sierra Trading Post Shopping Apps (Android and iPhone/iPad/iPod Touch) Smudges, a distraction game for little ones (Android and iPhone/iPad/iPod Touch) Sierra Trading Post API Sierra Trading Post mobile website StackGeography.com ([stackapps listing], [source]) Kickstarterterest ([source])

Updated on July 09, 2022

Comments

  • patridge
    patridge almost 2 years

    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.

  • Greg Shackles
    Greg Shackles almost 12 years
    You can often get better error messages for that kind of thing by increasing the build verbosity: docs.xamarin.com/android/…
  • PCoder
    PCoder over 11 years
    +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.
  • Aiden Strydom
    Aiden Strydom almost 11 years
    I just had a space in the name of my drawable.... I removed it and bob's your uncle
  • Leon Cullens
    Leon Cullens about 8 years
    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.
  • vikingben
    vikingben over 7 years
    I had a hyphen in an image name was causing this error.
  • Stefan Babos
    Stefan Babos about 7 years
    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.
  • SharpC
    SharpC about 7 years
    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.