39

I've been diving into Android development for a while, and now I want to use some project (helpshift) in my app. On the website they have some example apps in which the readme says: Run the following inside the /HelpshiftDemo folder.

android update project -t android-17 -p .

So I do this, but unfortunately this gives me an error saying -bash: android: command not found. I understand this, because "android" as such doesn't refer to anything on my laptop (Mac OSX). So I thought it is maybe referring to the adb. So I tried replacing android for the direct path to my adb:

/Users/kramer65/dev/adt-bundle-mac-x86_64-20130917/sdk/platform-tools/adb update project -t android-17 -p .

This gives me a humongous output with more information on adb, which is I guess not the expected result.

So my questions; what does android refer to, and how can I fix this on Mac OSX?

kramer65
  • 50,427
  • 120
  • 308
  • 488

10 Answers10

88

The android tool is located in the tools directory in your SDK. You need to add this to your PATH environment variable so that bash can recognize it.

You can do this by adding it to your PATH in your .bash_profile file. This file should be located in your home directory. Create if it doesn't exist using vi .bash_profile and add the following line to it:

export PATH=<path_to_android_sdk>/platform-tools:<path_to_android_sdk>/tools:$PATH

where <path_to_android_sdk> is to be replaced with the path to your SDK. For example: "/Users/me/android-sdk-mac_86/platform-tools"

Anup Cowkur
  • 20,443
  • 6
  • 51
  • 84
  • 5
    Worked perfectly for me! Of course you have to make sure that you remove the '<' and '>' as well as the text. My path was /Users/my_user_name/android-sdks so my total added to my .bash_profile was literally: export PATH=/my_user_name/android-sdks/platform-tools:/my_user_name/android-sdks/tools:$PATH – Jono Jul 31 '14 at 18:45
  • This worked for me previous, but with the last update to OS X Mavericks it stopped. I still see the entries in the PATH, but adb cannot be resolved. It works if I run it locally via ./adb but not with just 'adb'. – Splaktar Oct 17 '14 at 17:05
  • I have to added following Line : export PATH=/User/username/Library/Android/sdk/platform-tools:/User/username/Library/Android/sdk/tools:$PATH restard my terminal, but still not working :( help – Nininea Feb 18 '16 at 09:35
  • oops , my fault - I had to write Users instead of User in the path ^_^ it works perferct – Nininea Feb 18 '16 at 09:39
  • 2
    Does this still work in Catalina? I can't get this to work. – Berry Blue Dec 19 '19 at 16:20
31

Step 0

The first step is install Android SDK: https://developer.android.com/studio

I don't like the default configurations. I installed SDK in this folder:

/Users/<Username>/Android\ SDK

ℹ️ The default path is

$HOME/Library/Android/sdk

Step 1

The next command open your bash or zshrc configuration file:

Bash profile:

vim ~/.bash_profile

If you use zsh:

vim ~/.zshrc

Step 2

You're ready to update your configurations:

# File: .bash_profile | .zshrc

# Custom path to Android SDK folder. 
# If you use the default configuration please change ANDROID_HOME to $HOME/Library/Android/sdk
export ANDROID_HOME=/Users/<Username>/Android\ SDK
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH

Step 3

Option 1: Restart your terminal and you should be able to use android command

Option 2: source your bash or zsh profile.

Example: source ~/.bash_profile / source ~/.zshrc

d.danailov
  • 9,594
  • 4
  • 51
  • 36
  • 2
    I installed Android Studio from http://developer.android.com/sdk/index.html with the default options and the value for ANDROID_HOME needed to be `export ANDROID_HOME=$HOME/Library/Android/sdk` – Bruno Bronosky Feb 10 '15 at 17:46
  • Do you see my comment? "# !!! Change this configuration path. I install Android SDK in my local Mac directory." – d.danailov Feb 10 '15 at 17:55
  • 1
    I see your comment and raise you the information needed for a default Android Studio install. Telling people they need to change it doesn't tell them what to change it to or how to find the answer. I'm just trying to help people out. It's not an indictment. It would be useful to tell people they can find the (uniquely and consistently named) platform-tools folder via `find / -name platform-tools 2>/dev/null` and the parent folder will be the sdk/ANDROID_HOME path. – Bruno Bronosky Feb 10 '15 at 20:34
  • thix this worked perfectly for me! just for reference, this is what i added to my .bash_profile and then restarted the terminal: export ANDROID_HOME=$HOME/Library/Android/sdk export PATH=$HOME/Library/Android/sdk/tools:$PATH export PATH=$HOME/Library/Android/sdk/platform-tools:$PATH – nerdess Jun 18 '15 at 22:04
  • Great but restarting terminal wasn't enough for me, I needed to run `source ~/.bash_profile` – Phil Hudson Jan 11 '16 at 10:29
  • Add information for bash and zsh. @PhilHudson thank you very much. – d.danailov Jan 11 '16 at 10:36
  • 3
    In 2018, the Android SDK install path on OSX is /Users//Library/Android/sdk – pmont Feb 26 '18 at 21:36
  • 1
    This should no longer be a top answer, this path is out of date and not correct. – slothstronaut Dec 27 '19 at 05:43
  • @Eduardo thank you very much for the commend and for the feedback. I've updated my answer. Do you think the current version is helpful ? – d.danailov Dec 28 '19 at 09:04
23

I spent so much time trying to figure out, this steps helped me ( from http://docs.phonegap.com/en/2.2.0/guide_getting-started_android_index.md.html ) You need to execute your .bash_profile to update your PATH.

Set up your PATH environment variable on Mac OS

Open the Terminal program (this is in your Applications/Utilites folder by default). Run the following command

touch ~/.bash_profile; open ~/.bash_profile

This will open the file in the your default text editor. You need to add the path to your Android SDK platform-tools and tools directory. In my example I will use "/Development/android-sdk-macosx" as the directory the SDK is installed in. Add the following line:

export PATH=${PATH}:/Development/android-sdk-macosx/platform-tools:/Development/android-sdk-macosx/tools

Save the file and quit the text editor. Execute your .bash_profile to update your PATH:

source ~/.bash_profile

Now every time you open the Terminal program you PATH will included the Android SDK.

Community
  • 1
  • 1
Ben
  • 231
  • 2
  • 3
  • Thank you! This actually helped me get it working. The other answers were probably correct but this helped me identify what I was doing wrong and was also much simpler to set up! – brentonstrine Nov 15 '14 at 00:56
  • Awesome this is the best way to correct the problem and the simplest. This also highlighted a new issue. I installed Android Studio and updated through the SDK manger within the IDE. After following your instructions and getting the _'android'_ command to work it brought up another SDK manger view that showed the API's i previously updated in Android Studio were not actually updated. Not sure how I have two SDK instances or where that disconnect is. – Laser Hawk Jul 27 '15 at 20:52
11

Problem Solved For Android Studio Users:

I am using Mac OS X Elcapitan version 10.11.X.

Under my home directory I found .bash_profile.save file. I opened that file using sublime (you can use any other editor). Then I added this line

export PATH=${PATH}:/Users/UserName/Library/Android/sdk/platform-tools:/Users/UserName/Library/Android/sdk/tools

Replace "UserName" with your UserName.

open terminal then run

 source ~/.bash_profile 

here you go.

Muhammad Adil
  • 4,358
  • 3
  • 32
  • 36
6

First add these lines to your ~/.bashrc file:

export ANDROID_HOME=${HOME}/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools

then:

source ~/.bashrc
Hossam Mourad
  • 4,369
  • 4
  • 26
  • 22
4
export PATH="/Users/me/Library/Android/sdk/platform-tools/":"/Users/me/Library/Android/sdk/tools/":$PATH

Worked for me

thor
  • 21,418
  • 31
  • 87
  • 173
4

Add the following lines into ~/.bash_profile and source ~/.bash_profile

export ANDROID_HOME=/Users/macbook/Library/Android/sdk/
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH

This is working for me

2

Update the path.

Open the Terminal program from Spotlight. Run the following command:

touch ~/.bash_profile; open ~/.bash_profile

Then save following code

export PATH=${PATH}:/android-sdk-macosx/platform-tools:/Development/android-sdk-macosx/tools

For my case, path is

export PATH=/Users/<user-name>/Development/android-sdk-macosx/platform-tools:/Users/<user-name>/Development/android-sdk-macosx/tools:$PATH 

Save the file and quit the text editor. Execute your .bash_profile to update your PATH:

source ~/.bash_profile

Then run adb.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Bibin Baby
  • 163
  • 1
  • 3
2

This is the issue because of you didn't give proper android sdk path variable in .bash_profile. for this you must follow the below steps.
1. Check android sdk path: for this you should open android studio->preferences and click on Android SDK in newly open window in that look for Android SDK location textfield in that you can find path of Android SDK. For me it shows like: /Users/<your_name>/Library/Android/sdk. here <your_name> is name of your home directory.
2. Open your terminal enter cd ~ command.
3. and enter vi .bash_profile.
4. In vi editor enter following
export ANDROID_HOME=/Users/Murali/Library/Android/sdk export PATH=$ANDROID_HOME/tools:$PATH export PATH=$ANDROID_HOME/platform-tools:$PATH
Save it by press esc button and enter :wq.
5. After this close your terminal and open it again. 6. To apply all your changes in .bash_profile enter following command
source .bash_profile.
7. Enter android command. Hope this now working fine :-)

0

Update the path.

Open the Terminal program from Spotlight. Run the following command:

touch ~/.zshrc (or ~/.bash_profile) ; open ~/.zshrc (or ~/.bash_profile)

Then save following code

export AAPT_HOME=/Users/****/Library/Android/sdk/build-tools/31.0.0
export PATH=$PATH:$AAPT_HOME

Save the file and quit the text editor. Execute your .zshrc (or .bash_profile) to update your PATH:

source ~/.zshrc (or ~/.bash_profile)
Saeid Parvizi
  • 21
  • 1
  • 5