android – How to diagnose "Error executing aapt" error in Eclipse?-ThrowExceptions

Exception or error:

I’m ready to tear my hair out because I can’t get Eclipse unstuck from a state where it thinks it can’t find aapt:

Error executing aapt. Please check aapt is present at /usr/local/android-sdk-linux_x86/platform-tools/aapt

I’ve found a bunch of posts on this subject, which suggest deleting the error in the Eclipse UI, deleting R.java, rebuilding the project, restarting Eclipse, etc. These things help temporarily, but as soon as I edit an XML file, Eclipse gets borked again. It’s getting really annoying to rebuild all my source and restart Eclipse every time I change an XML file.

aapt is clearly there:

$ ls -l /usr/local/android-sdk-linux_x86/platform-tools/aapt
-rwxr-xr-x 1 boris boris 3764858 2011-07-28 11:50 /usr/local/android-sdk-linux_x86/platform-tools/aapt

Is there a way to know exactly what the error is that’s occurring? I tried looking in the Eclipse console output and in .metadata/.log in my project and didn’t see anything related.

How to solve:

Hit this again today, and discovered that verbose output from aapt doesn’t help. It just spits out the aapt command to the console and fails without an error.

I think I’ve finally gotten to the bottom of what’s going wrong. I believe that aapt is failing due to insufficient memory. My Eclipse process was using 1.2GB of memory. When Eclipse runs aapt, it forks the process which, from what I understand, allocates another 1.2GB just for running aapt.

I looked at my process list, and saw that Firefox was using almost 400MB of memory. I killed Firefox, and then aapt started working. Crazy.

###

Finally found the answer to my question here:

http://groups.google.com/group/android-developers/browse_thread/thread/bad9d488d2068260

Turns out that you can see the aapt command and output by setting “Build output” to “Verbose” in Preferences/Android/Build. Weird that they don’t spit out the output when an error occurs.

###

In my case (fresh Eclipse installation, new project generated with wizard, errors like “Couldn’t resolve R to variable”) the problem turned out to be with absense of trailing slash in path to Android SDK at Preferences->Android.

###

Hint (suggested by Eclipse on Ubuntu): On 64-bit systems, make sure the 32-bit libraries are installed: sudo apt-get install ia32-libs

That has solved my problem !

###

I had this because of a misdeclared ID in one of the resources files. I’m using Android Studio (but not gradle), and I had in a style declaration a reference to an @+id/... which isn’t allowed, apparently. I had to declare the ID in another values xml files as <item type="id" name="..." />.

###

This error can be caused by an invalid drawable id, such as

        android:icon="@drawable/ic_action_search_whatever"

If there is no drawable called ic_action_search_whatever aapt will die. Simple error, but not an easy one to debug!

###

In my case, the “Android SDK Build Tools” (version 20.0) was broken somehow. So I updated the tool to the latest one(21.1) using the “Android SDK Manager” & voila – it got OK :).

###

Aapt is a 32bit application. I am running ubuntu 64bit. I needed some additional libraries.
To get aapt working (this fixed my issues with the avd as well) just run these two commands:

sudo apt-get install lib32stdc++6

sudo apt-get install lib32z1

Enjoy

###

I actually noticed that I had converted my jpg file to png file that’s why the aapt error was coming.

Leave a Reply

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