6

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.

Dre
  • 2,933
  • 2
  • 18
  • 21

1 Answers1

28

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"
Community
  • 1
  • 1
Eliot
  • 5,450
  • 3
  • 32
  • 30
  • I think you're onto something; running `which` showed me another instance of `aapt`. I'm going to try removing it and see if that resolves my issue. – Dre Nov 28 '13 at 19:16
  • Excellent: `which aapt` revealed that it was trying to run the command from the wrong location (presumably the tools must have been installed in a different location at some point and then deleted, but the alias remained). Removing the alias and updating the `~/.bash_profile` as described worked. That's the first time I've encountered `which`; that's a handy command. Thanks! – Dre Nov 28 '13 at 19:25
  • 2
    I find it helpful to store the build tools version as a separate variable in my profile. For example... export ANDROID_BUILD_TOOLS_VERSION=22.0.1 ...so you can easily point to a different version without changing the PATH and other variables directly... export ANDROID_BUILD_TOOLS_HOME=$ANDROID_SDK_HOME/build-tools/$ANDROID_BUILD_TOOLS_VERSION ... export PATH=$PATH:$ANDROID_SDK_TOOLS_HOME:$ANDROID_BUILD_TOOLS_HOME ... etc. – Devon Biere Jul 23 '15 at 11:16
  • Worked perfectly. This saved me so much time.. Thank you! – Seth Jul 28 '15 at 20:50
  • 1
    You could use the following to get the latest build-tools without modifying each time: `PATH="${ANDROID_HOME}/build-tools/$(ls ${ANDROID_HOME}/build-tools | sort -r | head -n 1):${PATH}" ` – Jared Rummler Nov 08 '16 at 00:19
  • @JaredRummler that's awesome, great idea! I updated my answer with my take on dynamic build-tool resolution. – Eliot Nov 18 '16 at 16:57