[android] Set up adb on Mac OS X

I spent quite sometime figuring how to set up adb on Mac, so I figure writing how to set it up might be useful to some people. adb is the command line tool to install and run android apps on your phone/emulator

This question is related to android macos adb

The answer is


NOTE: Path for adb has changed since Android Studio 1.0.xx

For bash shell, use:

echo 'export PATH=$PATH:'$HOME'/Library/Android/sdk/platform-tools' >> ~/.bash_profile

For tcsh shell, use:

echo 'setenv PATH $PATH\:'$HOME'/Library/Android/sdk/platform-tools' >> ~/.tcshrc

Here is a step wise information :

Step-1

Start up Terminal and go to your home folder.

cd ~/

Step-2

Open and edit .bash_profile file

$ open -e .bash_profile

If you don’t have .bash_profile file in your computer path, then create one. Enter below command to create a new file. Once created follow Step-2.

touch .bash_profile

Step-3

Save the below line)

export PATH=${PATH}:/Applications/adt-bundle-mac-x86_64-20140321/sdk/tools
export PATH=${PATH}:/Applications/adt-bundle-mac-x86_64-20140321/sdk/platform-tools

Step-4

Refresh the file using below command

$ source .bash_profile

$ echo $PATH

You should see your android path set in the output now.


In my case : I did the following (on a mac) :

  1. backed up the ".bash_profile" and ".profile"
  2. cleared all the android related paths.
  3. created the new paths but this time around, I dragged the respective folders : { /.../sdk, /.../tools, /.../platform-tools } into the terminal. I did this for both ".bash_profile" and ".profile".
  4. Then after successfully saving the files each. I restarted the terminal just to be sure about the modifications I made.
  5. I then went on to test if adb was responding now ... by typing : (in terminal) adb devices
  6. I still had no luck (my devices) where not showing, then I restarted the adb, still.
  7. I went on to do "android update adb" . This just killed and restarted the adb
  8. I tried again still the devices wasnt showing.
  9. I totally backed up my android device and resetted the whole phone back to factory default, went over to activate the device for development and allow for usb debugging in its settings > applications.

******** WORKED LIKE A CHARM ********

I tried again with the command "adb devices" and everything was back to normal the device was visible.

All the best. Just dont give up. It took me a lot of troubleshooting. All the best of luck.


Only for zsh users in iterm2 in macOS

type the following two commands to add the android sdk and platform-tools to your zsh in iterm2 in macOS

echo 'export ANDROID_HOME=/Users/$USER/Library/Android/sdk' >> ~/.zshrc
echo 'export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools' >> ~/.zshrc

After adding the two command to ~/.zshrc you need to source the zsh.

source ~/.zshrc

Here's a detailed manual:
http://codexpi.com/add-android-adb-path-mac-os-x-mavericks/

To sum this up:

  1. Create and open the bash_profile file

    touch .bash_profile
    open -e .bash_profile

  2. Add the path of the platform-tools folder (within the Android SDK)

    export PATH="$PATH:/Users/USERNAME/PATH TO ANDROID SDK/platform-tools/

  3. Run the command . .bash_profile to update (no need to restart the terminal)


In my case, I installed Android studio, and have some apps (rust lang) that changes the ~/.profile, and adding adb to ~/.bash_profile made the rust un-executable, so I made the changes to the ~/.profile only, as:

$ echo 'PATH=$PATH:$HOME/Library/Android/sdk/platform-tools/' >> ~/.profile
$ source ~/.profile
$ adb --version
Android Debug Bridge version 1.0.41
Version 29.0.4-5871666
Installed as /Users/hasan/Library/Android/sdk/platform-tools/adb

Download Andriod Platform Tools for macOS from:

https://developer.android.com/studio/releases/platform-tools

Extract to your somewhere e.g ~/installs/platform-tools

Add that folder to path by running:

echo 'export PATH=$PATH:~/installs/platform-tools' >> ~/.zshrc

Either restart terminal or run:

source ~/.zshrc

Assuming that you are using zsh.


This totally worked for me, after dickering around for a while after installing Android Studio:

  1. Make sure you have the .bash_profile file. This should be in your [username] directory.

  2. From whatever directory you are on, type this:

    echo "export PATH=\$PATH:/Users/${USER}/Library/Android/sdk/platform-tools/" >> ~/.bash_profile
    

Now, usually you will have this exact path, but if not, then use whatever path you have the platform-tools folder

  1. From the directory where your .bash_profile resides, type this:

    . .bash_profile
    
  2. Now type adb devices. You should see a "List of devices attached" response. Now you do not have to go to the platform-tools directory each and every time to type in the more cryptic command like, ./adb devices!!!


Mac OS Open Terminal

touch ~/.bash_profile; open ~/.bash_profile

Copy and paste:

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

command + S for save.


If you are setting the path in Catalina use below command one after another in the terminal. It's working fine for me.

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

source ~/.bash_profile

Personally I just source my .bashrc in my .bash_profile:

echo 'source ~/.bashrc' >> ~/.bash_profile

So I put it in my .bashrc. And I'm using Android Studio, so it was a different path.

echo 'PATH=$PATH:$HOME/Library/Android/sdk/platform-tools/' >> ~/.bashrc

You may also want the following:

echo 'ANDROID_HOME=$HOME/Library/Android/sdk' >> ~/.bashrc

This Works Flawless....

In terminal Run both commands next to each other

export ANDROID_HOME=/Users/$USER/Library/Android/sdk

export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

If you are using ZSH and have Android Studio 1.3: 1. Open .zshrc file (Located in your home directory, file is hidden so make sure you can see hidden files) 2. Add this line at the end: alias adb="/Users/kamil/Library/Android/sdk/platform-tools/adb" 3. Quit terminal 4. Open terminal and type in adb devices 5. If it worked it will give you list of all connected devices


After trying all the solutions, none of them where working for me.

In my case I had the Android Studio and the adb was correctly working but the Android Studio was not capable to detect the adb. These was because I installed it with homebrew in another directory, not the /Users/$USER/Library/Android/sdk but Usr/Library blabla

Apparently AS needed to have it in his route /Users/$USER/Library/Android/sdk (same place as in preferences SDK installation route)

So I deleted all the adb from my computer (I installed several) and executed these terminal commands:

echo 'export ANDROID_HOME=/Users/$USER/Library/Android/sdk' >> ~/.bash_profile
echo 'export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools' >> ~/.bash_profile
source ~/.bash_profile
adb devices

Well, after that, still wasn't working, because for some reason the route for the adb was /Users/$USER/Library/Android/sdk/platform-tools/platform-tools (yes, repeated) so I just copied the last platform-tools into the first directory with all the license files and started working.

Weird but true


Add environment variable for Android Home Targetting Platform Tools

echo 'export ANDROID_HOME=/Users/$USER/Library/Android/sdk' >> ~/.bash_profile

echo 'export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools' >> ~/.bash_profile

Restart Bash

source ~/.bash_profile

Now Check adb

Simply type

adb

on terminal


cd sdk/platform-tools/ and then use ./adb devices instead


For Mac users : Step 1: Install the Android Studio

Step2 : Open the terminal and type

cd

Step 3: Type below mentioned command changing the userName:

export PATH=“/Users/{user_name}/Library/Android/sdk/platform-tools”:$PATH

Commenting with some updated information from 2018.

Executable Binaries for Platform tools are made available for mac by Android here: https://developer.android.com/studio/releases/platform-tools.html

Download these to your mac. Place them in a directory e.g. I placed in ~/Software/platform-tools

If you have root access, the easiest way I have found on a mac is to add your directories to the list in /etc/paths. I like this way because after a few additions the $PATH starts to look too messy and hard to read, the /etc/pathshas everything in separate line, clean and organized. The downside is that you require root access.

$ cat /etc/paths  # check contents of the file
$ sudo nano /etc/paths

Paste the full path of your platform-tools directory (something like /Users/GodZilla/Software/platform-tools/adb) at the end of this list and save. Quit and Open terminal again and check if it sees your platform-tools directory.

$ which adb
/Users/GodZilla/Software/platform-tools/adb
$ which fastboot
/Users/GodZilla/Software/platform-tools/fastboot

If you don't have root access, just add the platform-tools directory to $PATH in your .bash_profile (or .zshenv if you use zsh) as other users have suggested.


MacPorts

It seems like android-platform-tools was first added to MacPorts only very recently — in 2018-10-20, under java/android-platform-tools/Portfile:

It would appear that it relies on a compiled binary that's provided by Google; it would appear that the source code for the binary might not be available.

The adb binary

Reverse-engineering the android-platform-tools/Portfile from above reveals that the following archive is fetched from Google in order to build the port:

The abd binary is pre-compiled, available in platform-tools/adb within the above archive, which is a Mach-O 64-bit executable x86_64, as per file(1). It's ready to be used and doesn't seem to have any external dependencies (e.g., doesn't look like it depends on java or anything).

Using adb

In order to use adb to restart the device, for example, in case the power button is stuck, the following steps could be used:

cd /tmp
curl https://dl.google.com/android/repository/platform-tools_r28.0.1-darwin.zip -o apt.zip
unzip apt.zip
./platform-tools/adb devices
./platform-tools/adb reboot

Upon first use since a reboot, you also have to first confirm the pairing with the phone through the Allow USB debugging? popup on the phone (phone has to have USB debugging enabled through the Developer Options, no root access required).


Considering you have already downloaded SDK platform tools.

This command will set ADB locally. So if you close the terminal and open it again, ADB commands won't work until you run this command again.

export PATH=~/Library/Android/sdk/platform-tools:$PATH

These commands will set ADB globally. So once you run these commands no need to set them again next time.

echo 'export PATH=$PATH:~/Library/Android/sdk/platform-tools/' >> ~/.bash_profile

source ~/.bash_profile

Step 1 : Open Terminal

Step 2 : Run command :

 touch ~/.bash_profile; open ~/.bash_profile

Step 3 : This will open textEdit file when you can add following command:

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

Blockquote

Note : sharan is my user name check that on y our system and replace that with sharan rest will be same. You can also find that by opening android studio

   File->Project Structure..->SDK Location

Under Android SDK location there is path of sdk copy that and paste that on file and save it by pressing Command+S


For macOS Users Updated to MacOs Catalina,

~/.bash_profile changed to ~/.zshrc

So ,to run adb command and all other commands already exported to ~/.bash_profile easy walkaround is to export bash_profile to zshrc

To do that,

1) Navigate to the home directory in finder

2) I used Cmd + Shift + . to show the hidden files in Finder

3) Create .zshrc file if already not exist

4) Add line "source ~/.bash_profile" without quotes

5) Save

6) Quit and open terminal

start using adb devices


echo "export PATH=\$PATH:/Users/${USER}/Library/Android/sdk/platform-tools/" >> ~/.bash_profile && source ~/.bash_profile

If you put the android-sdks folder in other directory, replace the path with the directory android-sdks/platform-tools is in


The simplest way to use adb command on your Mac systems would be to add the path to the platform-tools (where adb lives) into your bash_profile.

Steps to add the adb path: 1. open the bash_profile: This can be done by using the following commands

open ~/.bash_profile

This opens up the bash_profile in an editor.

  1. Locate the platform_tools, usually they are present at the following location: Users/"user_folder"/Library/Android/sdk/platform_tools

  2. Paste the following command in the bash_profile file which opens up:

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

  3. Save the file using the command:

source ~/.bash_profile

  1. Check if the path is saved by typing: echo $PATH : You should be able to find the entire path displayed in the output.

  2. Type adb to see if the configuration worked. If you have any devices connected to the machine or any emulators running on your system they would be displayed when you type adb devices

output for adb devices


if you are using Android Studio in MAC OS X , you could exec the following command in your terminal app:

echo 'alias adb="/Applications/Android\ Studio.app/sdk/platform-tools/adb"' >> .bashrc
exec $SHELL

and next:

adb devices

and you should be showing a list with your android devices connected via USB cable in your MAC, for example something like this:

* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
deb7bed5        device

If you are using zsh terminal do the following:

1) Open .zprofile file with the editor of your choice like "open -a xcode ~/.zprofile"

2) Add new PATH or Env Variable in .zprofile Save the file and quit the editor.

3) Execute your .zprofile to update your PATH: source ~/.zprofile


If you using zsh then you need do the add the following to your .zshrc

Steps: Step 1: Open your .zshrc profile

open -e .zshrc

Step 2: Add the following to the file

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

Step 3: Save the file and close. Step 4: Reload the .zshrc

source .zshrc

Step 5: Check the devices connected

adb devices

Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to macos

Problems with installation of Google App Engine SDK for php in OS X dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac Could not install packages due to an EnvironmentError: [Errno 13] How do I install Java on Mac OSX allowing version switching? Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) How can I install a previous version of Python 3 in macOS using homebrew? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'"

Examples related to adb

ADB server version (36) doesn't match this client (39) {Not using Genymotion} ADB device list is empty "unable to locate adb" using Android Studio Run react-native on android emulator Solving "adb server version doesn't match this client" error Adb install failure: INSTALL_CANCELED_BY_USER Session 'app': Error Installing APK Where is adb.exe in windows 10 located? How to debug in Android Studio using adb over WiFi Set adb vendor keys