Dre Dre - 19 days ago 6
Android Question

Unable to run aapt command - keeps returning "Android SDK Build-tools"

What I'm attempting to do: Install the Android build tools on Mac OSX so I can use the

aapt
command to crunch/process some images for testing

What I've done:


  1. Installed the Android SDK using brew

  2. Run the
    android
    command to bring up the SDK Manager

  3. Used the Manager to install the SDK tools (22.3), SDK Platform-tools(19), SDK Build-tools(19) and Android 4.4

  4. I've verified that the tools were added to the default location when using brew.



What happens:
Running
aapt
or
aapt v
always returns
Use the 'android' tool to install the "Android SDK Build-tools".


I've also tried updating the tools using
android update
, but it still fails to work.

EDIT:
Running the full path to
aapt v
works. I'm now assuming I have an issue with my
PATH
which I still need to resolve

Any clues as to what to try next would be greatly appreciated.

Answer

I'm pretty sure that the Android SDK doesn't try to modify your PATH variable for you. If you want to be able to run SDK tools without specifying their full path, you'll need to add the folder(s) containing them to your PATH one by one.

You can do this by editing your ~/.bash_profile and adding a line like so (or editing an existing line like this if you have one already):

export PATH="$PATH:/PATH/TO/android-sdk-macosx/build-tools/17.0.0"

Alternatively, you can just specify the full path to the tool when invoking it, like so:

/PATH/TO/android-sdk-macosx/build-tools/17.0.0/aapt v

I'm not sure this ever happens with aapt, but this can be useful to disambiguate if multiple versions of a tool are installed. To see which version of a command that bash is resolving to, you can usually find out by running which, like so:

which aapt

EDIT

There have been a number of good comments on this answer including Jared's excellent suggestion to dynamically add the latest build-tools to the path. I reimplemented his code in pure 3.x bash, here's what's currently in my ~/.bash_profile. First, make sure to set ANDROID_HOME:

export ANDROID_HOME="$HOME/Library/Android/sdk" #Set this to the path to your Android SDK if it's not in the default location

Then (if you are using bash):

BUILD_TOOLS=($ANDROID_HOME/build-tools/*)
ANDROID_LATEST_BUILD_TOOLS="${BUILD_TOOLS[@]:(-1)}"
export PATH="$PATH:$HOME/bin:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_LATEST_BUILD_TOOLS"

Alternatively, here is a POSIX version that should work in any shell:

ANDROID_LATEST_BUILD_TOOLS=$(ls -r ${ANDROID_HOME}/build-tools|head -1)
export PATH="$PATH:$HOME/bin:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools/$ANDROID_LATEST_BUILD_TOOLS"