Android command not found even PATH set - android

hi i am using ubuntu 12.04. and in ~/.bashrc file I set following things
export ANDROID_HOME=/home/nilkash/Downloads/android-sdk-linux/platform-tools
But still it gives me android: command not found error. how to set path for android. Need Help. Thank you.

To include the SDK's tools and platform-tools directories in your PATH environment open text editor to create or modify the ~/.bash_profile file, adding below line:
export PATH=${PATH}:/home/nilkash/Downloads/android-sdk-linux/platform-tools:/home/nilkash/Downloads/android-sdk-linux/tools
For Ubuntu:
To modify the PATH variable of your system, you need to edit your .bashrc file. To do so, in a terminal, execute the following command:
$ nano ~/.bashrc
You will now have the Nano text editor enabled on the terminal. Now, at the very top of the file, enter the following:
#AndroidDev PATH
export PATH=${PATH}:~/android-sdk-linux/tools
export PATH=${PATH}:~/android-sdk-linux/platform-tools
Once you're finished, press CTRL + X, Y, and then hit Enter to save your changes and exit the Nano text editor.
To reload the ~/.bashrc without re log in:
. ~/.bashrc or source ~/.bashrc
References:
- help.ubuntu.com/community/AndroidSDK- How do I reload .bashrc without logging out and back in?

1) Check in System Settings -> Details, whether your Ubuntu is 32-bit or 64-bit
2) If your Ubuntu is a 32-bit OS then run this sudo apt-get install libgl1-mesa-dev
In case of 64-bit OS run this sudo apt-get install ia32-libs
3) run this sudo apt-get install openjdk-6-jdk or better this sudo apt-get install openjdk-7-jdk
4) Download SDK platform tools from here http://developer.android.com/sdk/index.html
5) Unzip downloaded file "adt-bundle-linux-x86_64-20131030.zip" (you can have a little bit different name ;). But you should get folder contained two sub folder - sdk and eclipse
6) Run this nautilus ~
7) In opened window create folder 'android-sdk-linux'
8) copy the all entire contents of folder sdk (from unzipped archive) to this new folder 'android-sdk-linux'
9) try run this cd ~/android-sdk-linux/tools then this ./android. If you did all right you should see Android SDK Manager
10) run this sudo gedit ~/.bashrc in opened editor add this in very top
#AndroidDev PATH
export PATH=${PATH}:~/android-sdk-linux/tools
export PATH=${PATH}:~/android-sdk-linux/platform-tools
11) save and close
12) run exec bash then try run android
13) give write permissions to android-sdk-linux folder
Enjoy! ;)

android: command not found error
Solution for Linux and Mac:
1) Export your Android Sdk path to the ANDROID_HOME variable
$ export ANDROID_HOME=~/Android/Sdk (where ~/Android/Sdk is a full path to your Sdk folder)
(change "~" to "$HOME" on Mac)
2) Export Sdk tools to the PATH variable
$ export PATH=$ANDROID_HOME/tools:$PATH
That's it!

I tried
sudo nano /etc/profile
and appended these after the fi
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export ANDROID_HOME=/home/dev/Android/Sdk
export PATH=$PATH:$JAVA_HOME/bin:$ANDROID_HOME/platform-tools:ANDROID_HOME/tools
export JAVA_HOME
export ANDROID_HOME
and after saving the file
exec bash
these got my android command working, I had set PATH in .bashrc which was not working for me
Hope It'll help somebody

Environment variables can be defined permanently by editing the .profile file in your home directory. Here's how:
Edit your .profile file with a command like gedit ~/.profile. Append this to the end of the file:
export ANDROID_SDK_HOME=/home/nilkash/Downloads/android-sdk-linux/platform-tools
You can source .profile to make it apply right away. Each time you restart your system, the .profile file is loaded, restoring this setting.
OR
This below method works 100% for me on Ubuntu 12.04:
Start the terminal
$gedit .bashrc
Add the below line at the enc of the file:
PATH=$PATH:/home/nilkash/Downloads/android-sdk-linux/platform-tools/
Note: gedit must be performed only on .bashrc and NOT on .bashrc~
Please do accept the answer if it works for you.

if the problem still exist please make sure that you have the right permissions
try
sudo chmod -R 777 /home/your-user-name/.cordova/
Also make sure that you are NOT using sudo to add Android as a platform
This is incorrect in the default Cordova installation
sudo cordova platform add android
Just do
cordova platform add android

Related

Android Platform tools installed but still getting -bash: adb: command not found [duplicate]

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
Note: this was originally written on Installing ADB on macOS but that question was closed as a duplicate of this one.
Note for zsh users: replace all references to ~/.bash_profile with ~/.zshrc.
Option 1 - Using Homebrew
This is the easiest way and will provide automatic updates.
Install homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Install adb
brew install android-platform-tools
or try a cask install depending on your settings:
brew install --cask android-platform-tools
Start using adb
adb devices
Option 2 - Manually (just the platform tools)
This is the easiest way to get a manual installation of ADB and Fastboot.
Delete your old installation (optional)
rm -rf ~/.android-sdk-macosx/
Navigate to https://developer.android.com/studio/releases/platform-tools.html and click on the SDK Platform-Tools for Mac link.
Go to your Downloads folder
cd ~/Downloads/
Unzip the tools you downloaded
unzip platform-tools-latest*.zip
Move them somewhere you won't accidentally delete them
mkdir ~/.android-sdk-macosx
mv platform-tools/ ~/.android-sdk-macosx/platform-tools
Add platform-tools to your path
echo 'export PATH=$PATH:~/.android-sdk-macosx/platform-tools/' >> ~/.bash_profile
Refresh your bash profile (or restart your terminal app)
source ~/.bash_profile
Start using adb
adb devices
Option 3 - If you already have Android Studio installed
Add platform-tools to your path
echo 'export ANDROID_HOME=/Users/$USER/Library/Android/sdk' >> ~/.bash_profile
echo 'export PATH="$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools"' >> ~/.bash_profile
Refresh your bash profile (or restart your terminal app)
source ~/.bash_profile
Start using adb
adb devices
Option 4 - MacPorts
Install the Android SDK:
sudo port install android
Run the SDK manager:
sh /opt/local/share/java/android-sdk-macosx/tools/android
Uncheck everything but Android SDK Platform-tools (optional)
Install the packages, accepting licenses. Close the SDK Manager.
Add platform-tools to your path; in MacPorts, they're in /opt/local/share/java/android-sdk-macosx/platform-tools. E.g., for bash:
echo 'export PATH="$PATH:/opt/local/share/java/android-sdk-macosx/platform-tools"' >> ~/.bash_profile
Refresh your bash profile (or restart your terminal/shell):
source ~/.bash_profile
Start using adb:
adb devices
Option 5 - Manually (with SDK Manager)
Delete your old installation (optional)
rm -rf ~/.android-sdk-macosx/
Download the Mac SDK Tools from the Android developer site under "Get just the command line tools". Make sure you save them to your Downloads folder.
Go to your Downloads folder
cd ~/Downloads/
Unzip the tools you downloaded
unzip tools_r*-macosx.zip
Move them somewhere you won't accidentally delete them
mkdir ~/.android-sdk-macosx
mv tools/ ~/.android-sdk-macosx/tools
Run the SDK Manager
sh ~/.android-sdk-macosx/tools/android
Uncheck everything but Android SDK Platform-tools (optional)
Click Install Packages, accept licenses, click Install. Close the SDK Manager window.
Add platform-tools to your path
echo 'export PATH="$PATH:~/.android-sdk-macosx/platform-tools/"' >> ~/.bash_profile
Refresh your bash profile (or restart your terminal app)
source ~/.bash_profile
Start using adb
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
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
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
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
2022 Solution
If you have Android Studio installed already and Terminal isn't picking up ADB, here's a one-liner that should fix it:
sudo ln -s ~/Library/Android/sdk/platform-tools/adb /usr/local/bin
If you are using zsh shell and after trying all this solutions, you still need to set $PATH and $ANDROID_HOME every time you open new terminal instance, then here is your answer:
step 1: in terminal run nano ~/.zshrc
step 2: paste following command at the end of the file
export ANDROID_HOME=~/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH
step 3: After copying the lines above, to save hit control + X. and to confirm hit Y. It will ask you if you wish to change the file name but don't change the name so directly hit enter
step 4: Restart your terminal and execute the adb command.
Bingo!
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.
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
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.
Locate the platform_tools, usually they are present at the following location: Users/"user_folder"/Library/Android/sdk/platform_tools
Paste the following command in the bash_profile file which opens up:
export PATH=$PATH:/Users/A374375/Library/Android/sdk/platform-tools
Save the file using the command:
source ~/.bash_profile
Check if the path is saved by typing: echo $PATH : You should be able to find the entire path displayed in the output.
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
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
cd sdk/platform-tools/ and then use ./adb devices instead
On MacOS Big Sur do the following:
Open config file:
nano ~/.zshrc
Add paths to PATH variable:
export PATH=~/Library/Android/sdk/tools:$PATH
export PATH=~/Library/Android/sdk/platform-tools:$PATH
close file and save changes.
Then in terminal write:
source ~/.zshrc
And then you'll be able to run:
adb devices
adb kill-server
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
MAC Solution.
cd /Users/<user>/Library/Android/sdk/platform-tools
./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
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
Here's a detailed manual:
http://codexpi.com/add-android-adb-path-mac-os-x-mavericks/
To sum this up:
Create and open the bash_profile file
touch .bash_profile
open -e .bash_profile
Add the path of the platform-tools folder (within the Android SDK)
export PATH="$PATH:/Users/USERNAME/PATH TO ANDROID SDK/platform-tools/
Run the command . .bash_profile to update (no need to restart the terminal)
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
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
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.
Download Android 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:
Make sure you have the .bash_profile file. This should be in your [username] directory.
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
From the directory where your .bash_profile resides, type this:
. .bash_profile
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!!!
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
In my case : I did the following (on a mac) :
backed up the ".bash_profile" and ".profile"
cleared all the android related paths.
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".
Then after successfully saving the files each. I restarted the terminal just to be sure about the modifications I made.
I then went on to test if adb was responding now ...
by typing : (in terminal) adb devices
I still had no luck (my devices) where not showing, then I restarted the adb, still.
I went on to do "android update adb" . This just killed and restarted the adb
I tried again still the devices wasnt showing.
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.
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
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
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
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

Android PATH set up in the Mac OS

I use Mac OS and installed the Android SDK using the following command from the terminal,
brew tap caskroom/cask
brew cask install android-sdk
Then I updated the .bash_profile like
export ANDROID_HOME=/Users/Somename/Library/Android/sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Is the path is set up correctly and how can I test that?
That looks correct. You need to refresh your terminal with the contents of .bash_profile by either opening a new terminal window, or by typing
. ~/.bash_profile
Note the initial .. You can then check your path is correct by typing
echo $PATH
If all is correct, then you should be able to run binary tools within the Android SDK without specifying the full path, e.g.
adb devices
For reference, this is my own .bashrc file on my Debian machine:
export ANDROID_HOME=$HOME/Development/Android/sdk
export ANDROID_NDK_HOME=$HOME/Development/Android/android-ndk-r12b
export PATH=$PATH:$HOME/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_NDK_HOME

How to set ANDROID_HOME path in ubuntu?

How to set ANDROID_HOME path in ubuntu?
Please provide the steps.
In the console just type these :
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
If you want to make it permanent just add those lines in the ~/.bashrc file
I would like to share an answer that also demonstrates approach using the Android SDK provided by the Ubuntu repository:
Install Android SDK
sudo apt-get install android-sdk
Export environmental variables
export ANDROID_HOME="/usr/lib/android-sdk/"
export PATH="${PATH}:${ANDROID_HOME}tools/:${ANDROID_HOME}platform-tools/"
Assuming you have the sdk extracted at ~/Android/Sdk,
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
Add the above lines to the file ~/.bashrc (located at home/username/.bashrc) to make it permanent for the current user. Run source ~/.bashrc to apply the changes or restart your terminal.
(or)
Run the above lines on a terminal window to make it available for the session.
To test if you have set it up correctly,
Run the below commands on a terminal window
echo $ANDROID_HOME
user#host:~$ echo $ANDROID_HOME
/home/<user>/Android/Sdk
which android
user#host:~$ which android
/home/<user>/Android/Sdk/tools/android
Run android on a terminal window, If it opens up Android SDK Manager, you are good to go.
better way is to reuse ANDROID_HOME variable in path variable. if your ANDROID_HOME variable changes you just have to make change at one place.
export ANDROID_HOME=/home/arshid/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Initially go to your home and press Ctrl + H it will show you hidden files now look for .bashrc file, open it with any text editor then place below lines at the end of file.
export ANDROID_HOME=/home/varun/Android/Sdk
export PATH=$PATH:/home/varun/Android/Sdk/tools
export PATH=$PATH:/home/varun/Android/Sdk/platform-tools
Please change /home/varun/Android/Sdk path to your SDK path.
Do the same for tools and platform-tools.
After this save .bashrc file and close it.
Now you are ready to use ADB commands on terminal.
Add the following to your ~/.bashrc file. Log-out and log-in. I have my sdk in $HOME/Documents/Android/sdk you have to replace it with where you keep your sdk folder
# Android Path
PATH=$PATH:$HOME/Documents/Android/sdk:$HOME/Documents/Android/sdk/tools
export PATH
# For SDK version r_08 and higher, also add this for adb:
PATH=$PATH:$HOME/Documents/Android/sdk/platform-tools
export PATH
first open the .bashrc file by gedit ~/.bashrc
# Added ANDROID_HOME variable.
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
save the file and reopen the terminal
echo $ANDROID_HOME
it will show the path like /home/pathTo/Android/Sdk
Applies to Ubuntu and Linux Mint
In the archive:
sudo nano .bashrc
Add to the end:
export ANDROID_HOME=${HOME}/Android/Sdk
export PATH=${PATH}:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/tools
Restart the terminal and doing: echo $ HOME or $ PATH, you can know these variables.
Download the Android SDK to the machine. (Suppose that the location is /home/zelong/Android/Sdk) (home/username/Android/Sdk)
Add these lines to the file ~/.bashrc (located at home/username/.bashrc)
export ANDROID_HOME="/home/zelong/Android/Sdk"
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
This will make it permanent for the current user because every time the machine boots, it will run this script and set the enviroment path.
After making this change, remember to save it.
Then run source ~/.bashrc to apply the changes or restart your terminal.
Test if it works:
zelong#zelong-ThinkPad-T430:~$ echo $ANDROID_HOME
/home/zelong/Android/Sdk
zelong#zelong-ThinkPad-T430:~$ which android
/home/zelong/Android/Sdk/tools/android
zelong#zelong-ThinkPad-T430:~$ which adb
/home/zelong/Android/Sdk/platform-tools/adb
As we can see,
android command line locates under tools
adb command line locates under platform-tools
This is what work for me,
Assuming you have the sdk extracted at ~/Android/Sdk,
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
Add the above lines to the file ~/.bashrc (located at home/username/.bashrc) to make it permanent for the current user. Run source ~/.bashrc to apply the changes or restart your terminal.
(or)
Run the above lines on a terminal window to make it available for the session.
To test if you have set it up correctly,
Run the below commands on a terminal window
echo $ANDROID_HOME
user#host:~$ echo $ANDROID_HOME
You will get
/home/<user>/Android/Sdk
You can run this too
which android
user#host:~$ which android
/home/<user>/Android/Sdk/tools/android
Run android on a terminal, If it opens up Android SDK Manager, you are good to go.
you can edit the environment variable file in Ubuntu to set android home globally.
[1] run this command in terminal
sudo -H gedit /etc/environment
[2] your envirmnent file content will look like the below one
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
[3] in environment file add android sdk path as follows:-
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
ANDROID_HOME="/home/yourPathTo/Android/Sdk"
[4] then you can check the Android home path in the terminal with the following command:-
echo $ANDROID_HOME
If path is still not set then restart the system to get the applied changes.
In my case it works with a little change. Simply by putting :$PATH at the end.
# andorid paths
export ANDROID_HOME=$HOME/Android/Sdk
export PATH="$ANDROID_HOME/tools:$PATH"
export PATH="$ANDROID_HOME/platform-tools:$PATH"
export PATH="$ANDROID_HOME/emulator:$PATH"
In the terminal just type these 3 commands to set the ANDROID_HOME Variable :
$ export ANDROID_HOME=~/Android/Sdk
/Android/Sdk is the location of Sdk, this might get change in your case
$ PATH=$PATH:$ANDROID_HOME/tools
$ PATH=$PATH:$ANDROID_HOME/platform-tools `
Note : This will set the path temporarily so what ever action
you have to perform, perform on the same terminal.
If you run android with sudo it will install sdk in /root/Android/Sdk
so check if that is the case.
And if you are using dont run cordova with sudo it will look sdk in root also may be.
Above code for setting path is works fine.
I was facing the same problem with linux ANDROID_HOME path
Note:
1- Add parameters
2- Make or Rebuild project
3- Restart your PC
How to add parameters using terminal:
Open your terminal write
gedit .bashrc
another window will be open and then add the following lines at the end of the windows.
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
then back to terminal and type
source .bashrc
to save your changes in bashrc file at the end restart your computer.
add to file
~/.profile
export ANDROID_HOME=/opt/android-sdk
Path to the SDK
Then reset the computer
Had the same issue,
in the terminal you can type:
export ANDROID_HOME=$HOME/Android/Sdk
or any other location depending on where you installed the sdk.
export PATH=$PATH:$ANDROID_HOME/platform-tools
Hope it helps!
sudo su -
gedit ~/.bashrc
export PATH=${PATH}:/your path
export PATH=${PATH}:/your path
export PATH=${PATH}:/opt/workspace/android/android-sdk-linux/tools
export PATH=${PATH}:/opt/workspace/android/android-sdk-linux/platform-tools
You can append this line at the end of .bashrc file-
export PATH=$PATH:"/opt/Android/Sdk/platform-tools/"
here /opt/Android/Sdk/platform-tools/ is installation directory of Sdk.
.bashrc file is located in home folder
vi ~/.bashrc
or if you have sublime installed
subl ~/.bashrc
open ~/.bashrc file and paste at the end
export PATH=$PATH{}:/path-from-home-dir/android/sdk/tools
export PATH=$PATH{}:/path-from-home-dir/android/sdk/platform-tools

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
Note: this was originally written on Installing ADB on macOS but that question was closed as a duplicate of this one.
Note for zsh users: replace all references to ~/.bash_profile with ~/.zshrc.
Option 1 - Using Homebrew
This is the easiest way and will provide automatic updates.
Install homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Install adb
brew install android-platform-tools
or try a cask install depending on your settings:
brew install --cask android-platform-tools
Start using adb
adb devices
Option 2 - Manually (just the platform tools)
This is the easiest way to get a manual installation of ADB and Fastboot.
Delete your old installation (optional)
rm -rf ~/.android-sdk-macosx/
Navigate to https://developer.android.com/studio/releases/platform-tools.html and click on the SDK Platform-Tools for Mac link.
Go to your Downloads folder
cd ~/Downloads/
Unzip the tools you downloaded
unzip platform-tools-latest*.zip
Move them somewhere you won't accidentally delete them
mkdir ~/.android-sdk-macosx
mv platform-tools/ ~/.android-sdk-macosx/platform-tools
Add platform-tools to your path
echo 'export PATH=$PATH:~/.android-sdk-macosx/platform-tools/' >> ~/.bash_profile
Refresh your bash profile (or restart your terminal app)
source ~/.bash_profile
Start using adb
adb devices
Option 3 - If you already have Android Studio installed
Add platform-tools to your path
echo 'export ANDROID_HOME=/Users/$USER/Library/Android/sdk' >> ~/.bash_profile
echo 'export PATH="$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools"' >> ~/.bash_profile
Refresh your bash profile (or restart your terminal app)
source ~/.bash_profile
Start using adb
adb devices
Option 4 - MacPorts
Install the Android SDK:
sudo port install android
Run the SDK manager:
sh /opt/local/share/java/android-sdk-macosx/tools/android
Uncheck everything but Android SDK Platform-tools (optional)
Install the packages, accepting licenses. Close the SDK Manager.
Add platform-tools to your path; in MacPorts, they're in /opt/local/share/java/android-sdk-macosx/platform-tools. E.g., for bash:
echo 'export PATH="$PATH:/opt/local/share/java/android-sdk-macosx/platform-tools"' >> ~/.bash_profile
Refresh your bash profile (or restart your terminal/shell):
source ~/.bash_profile
Start using adb:
adb devices
Option 5 - Manually (with SDK Manager)
Delete your old installation (optional)
rm -rf ~/.android-sdk-macosx/
Download the Mac SDK Tools from the Android developer site under "Get just the command line tools". Make sure you save them to your Downloads folder.
Go to your Downloads folder
cd ~/Downloads/
Unzip the tools you downloaded
unzip tools_r*-macosx.zip
Move them somewhere you won't accidentally delete them
mkdir ~/.android-sdk-macosx
mv tools/ ~/.android-sdk-macosx/tools
Run the SDK Manager
sh ~/.android-sdk-macosx/tools/android
Uncheck everything but Android SDK Platform-tools (optional)
Click Install Packages, accept licenses, click Install. Close the SDK Manager window.
Add platform-tools to your path
echo 'export PATH="$PATH:~/.android-sdk-macosx/platform-tools/"' >> ~/.bash_profile
Refresh your bash profile (or restart your terminal app)
source ~/.bash_profile
Start using adb
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
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
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
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
2022 Solution
If you have Android Studio installed already and Terminal isn't picking up ADB, here's a one-liner that should fix it:
sudo ln -s ~/Library/Android/sdk/platform-tools/adb /usr/local/bin
If you are using zsh shell and after trying all this solutions, you still need to set $PATH and $ANDROID_HOME every time you open new terminal instance, then here is your answer:
step 1: in terminal run nano ~/.zshrc
step 2: paste following command at the end of the file
export ANDROID_HOME=~/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH
step 3: After copying the lines above, to save hit control + X. and to confirm hit Y. It will ask you if you wish to change the file name but don't change the name so directly hit enter
step 4: Restart your terminal and execute the adb command.
Bingo!
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.
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
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.
Locate the platform_tools, usually they are present at the following location: Users/"user_folder"/Library/Android/sdk/platform_tools
Paste the following command in the bash_profile file which opens up:
export PATH=$PATH:/Users/A374375/Library/Android/sdk/platform-tools
Save the file using the command:
source ~/.bash_profile
Check if the path is saved by typing: echo $PATH : You should be able to find the entire path displayed in the output.
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
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
cd sdk/platform-tools/ and then use ./adb devices instead
On MacOS Big Sur do the following:
Open config file:
nano ~/.zshrc
Add paths to PATH variable:
export PATH=~/Library/Android/sdk/tools:$PATH
export PATH=~/Library/Android/sdk/platform-tools:$PATH
close file and save changes.
Then in terminal write:
source ~/.zshrc
And then you'll be able to run:
adb devices
adb kill-server
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
MAC Solution.
cd /Users/<user>/Library/Android/sdk/platform-tools
./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
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
Here's a detailed manual:
http://codexpi.com/add-android-adb-path-mac-os-x-mavericks/
To sum this up:
Create and open the bash_profile file
touch .bash_profile
open -e .bash_profile
Add the path of the platform-tools folder (within the Android SDK)
export PATH="$PATH:/Users/USERNAME/PATH TO ANDROID SDK/platform-tools/
Run the command . .bash_profile to update (no need to restart the terminal)
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
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
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.
Download Android 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:
Make sure you have the .bash_profile file. This should be in your [username] directory.
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
From the directory where your .bash_profile resides, type this:
. .bash_profile
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!!!
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
In my case : I did the following (on a mac) :
backed up the ".bash_profile" and ".profile"
cleared all the android related paths.
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".
Then after successfully saving the files each. I restarted the terminal just to be sure about the modifications I made.
I then went on to test if adb was responding now ...
by typing : (in terminal) adb devices
I still had no luck (my devices) where not showing, then I restarted the adb, still.
I went on to do "android update adb" . This just killed and restarted the adb
I tried again still the devices wasnt showing.
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.
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
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
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
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

Not able to access adb in OS X through Terminal, "command not found"

I have installed Android SDK and Eclipse on my Mac system. I am able to program using Eclipse and have created few sample applications. But I am still not able to access adb through the terminal window. I have tried following command in terminal:
$ pwd
/Users/espireinfolabs/Desktop/soft/android-sdk-mac_x86/platform-tools
$ ls
NOTICE.txt dexdump llvm-rs-cc-2
aapt dx llvm-rs-cc.txt
adb lib source.properties
aidl llvm-rs-cc
$ adb --help
-bash: adb: command not found
I have also added the ls output so that you know in which window I am.
The problem is: adb is not in your PATH. This is where the shell looks for executables. You can check your current PATH with echo $PATH.
Bash will first try to look for a binary called adb in your Path, and not in the current directory. Therefore, if you are currently in the platform-tools directory, just call
./adb --help
The dot is your current directory, and this tells Bash to use adb from there.
But actually, you should add platform-tools to your PATH, as well as some other tools that the Android SDK comes with. This is how you do it:
Find out where you installed the Android SDK. This might be (where $HOME is your user's home directory) one of the following (or verify via Configure > SDK Manager in the Android Studio startup screen):
Linux: $HOME/Android/Sdk
macOS: $HOME/Library/Android/sdk
Find out which shell profile to edit, depending on which file is used:
Linux: typically $HOME/.bashrc
macOS: typically $HOME/.bash_profile
With Zsh: $HOME/.zshrc
Open the shell profile from step two, and at the bottom of the file, add the following lines. Make sure to replace the path with the one where you installed platform-tools if it differs:
export ANDROID_HOME="$HOME/Android/Sdk"
export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
Save the profile file, then, re-start the terminal or run source ~/.bashrc (or whatever you just modified).
Note that setting ANDROID_HOME is required for some third party frameworks, so it does not hurt to add it.
For zsh users. Add alias adb='/Users/$USER/Library/Android/sdk/platform-tools/adb' to .zshrc file.
Then run source ~/.zshrc command
run command in terminal nano $HOME/.zshrc
Must include next lines:
export PATH=$PATH:~/Library/Android/sdk/platform-tools
export ANDROID_HOME=~/Library/Android/sdk
export PATH="$HOME/.bin:$PATH"
export PATH="~/Library/Android/sdk/platform-tools":$PATH
Press Ctrl + X to save file in editor,Enter Yes or No and hit Enter key
Run source ~/.zshrc
Check adb in terminal, run adb
In addition to slhck, this is what worked for me (mac).
To check where your sdk is located.
Open Android studio and go to:
File -> Project Structure -> Sdk location
Copy the path.
Create the hidden .bash_profile in your home.
(open it with vim, or open -e) with the following:
export PATH=/Users/<Your session name>/Library/Android/sdk/platform-tools:/Users/<Your session name>/Library/Android/sdk/tools:$PATH
Then simply use this in your terminal: . ~/.bash_profile
SO post on how to find adb devices
Quick Answer
Pasting this command in terminal solves the issue in most cases:
** For Current Terminal Session:
(in macOS) export PATH="~/Library/Android/sdk/platform-tools":$PATH
(in Windows) i will update asap
** Permanently:
(in macOS) edit the ~/.bash_profile using vi ~/.bash_profile and add this line to it: export PATH="~/Library/Android/sdk/platform-tools":$PATH
However, if not, continue reading.
Detailed Answer
Android Debug Bridge, or adb for short, is usually located in Platform Tools and comes with
Android SDK, You simply need to add its location to system path. So system knows about it, and can use it if necessary.
Find ADB's Location
Path to this folder varies by installation scenario, but common ones are:
If you have installed Android Studio, path to ADB would be: (Most Common)
(in macOS) ~/Library/Android/sdk/platform-tools
(in Windows) i will update asap
If you have installed Android Studio somewhere else, determine its location by going to:
(in macOS) Android Studio > Preferences > Appearance And Behavior > System Settings > Android SDK and pay attention to the box that says: Android SDK Location
(in Windows) i will update asap
However Android SDK could be Installed without Android studio, in this case your path might be different, and depends on your installation.
Add it to System Path
When you have determined ADB's location, add it to system, follow this syntax and type it in terminal:
(in macOS)
export PATH="your/path/to/adb/here":$PATH
for example: export PATH="~/Library/Android/sdk/platform-tools":$PATH
I don't know how did you install the android SDK. But in Mac OS, what really worked for me is to reinstall it using brew. All problems solved in a row.
brew install --cask android-sdk
Later on:
android update sdk --no-ui --filter 'platform-tools'
Like a charm
This is how it worked for me
first I find my platform-tools than I was using zshrc instead of bash_profile so I run this command first
echo 'export PATH=${PATH}:$HOME/Library/Android/sdk/platform-tools/' >> ~/.zshrc
next refresh terminal
source ~/.zshrc
Check if it worked
adb devices
result of this command must be something similar to this if so then it worked.
List of devices attached
emulator-5554 device
For me, I ran into this issue after switching over from bash to zsh so I could get my console to look all awesome fantastic-ish with Hyper and the snazzy theme. I was trying to run my react-native application using react-native run-android and running into the op's issue. Adding the following into my ~.zshrc file solved the issue for me:
export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools
If you have installed Android Studio on MAC here is how:
nano ~/.zshrc
or
open ~/.zshrc in VScode
Then edit the file
# Android ADB
export ANDROID_HOME="$HOME/Library/Android/sdk"
export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
control + X OR Save file.
Restart Terminal and try
> adb
UPDATE
As #Loren.A mentioned in comment latest version of brew does not support cast. So one can simply use:
brew install android-platform-tools
Simply install adb with brew
brew cask install android-platform-tools
Check if adb is installed
adb devices
If you are using the Mac with the M1 chip add the below export command to the zshrc file using the nano command, if that file is not present the nano command will create it for you so run
nano ~/.zshrc
paste this path in that file without any modification
export PATH="/Users/$USER/Library/Android/sdk/platform-tools":$PATH
hit ctrl-x and then Hit y to save the changes and the hit return Key to close it without renaming the file.
then run
source ~/.zshrc
to refresh the .zshrc file
and then try runnning
adb
it should give you the desired output
If you are using zsh on an OS X, you have to edit the zshrc file.
Use vim or your favorite text editor to open zshrc file:
vim ~/.zshrc
Paste the path to adb in this file:
export PATH="/Users/{$USER}/Library/Android/sdk/platform-tools":$PATH
For Mac OS Catalina or Mojave
Enter command to open nano editor
nano $HOME/.zshrc
Set PATH variable, means append more path as shown here
FLUTTER_HOME="/Users/pankaj/Library/Android/flutter-sdk/flutter/bin"
DART_HOME="/Users/pankaj/Library/Android/flutter-sdk/flutter/bin/cache/dart-sdk/bin"
ANDROID_SDK_HOME="/Users/pankaj/Library/Android/sdk"
ANDROID_ADB_HOME="/Users/pankaj/Library/Android/sdk/platform-tools"
PATH="$PATH:$FLUTTER_HOME"
PATH="$PATH:$DART_HOME"
PATH="$PATH:$ANDROID_SDK_HOME"
PATH="$PATH:$ANDROID_ADB_HOME"
Now press Command + X to save file in editor,Enter Yes or No and hit Enter key.
This worked for me on my MAC - 2020
Go to directory containing adb:
cd ~/Library/Android/sdk/platform-tools/
Run adb command to list all services
./adb shell dumpsys activity services
I couldn't get the stupid path working so I created an alias for abd
alias abd ="~/Library/Android/sdk/platform-tools/adb"
works fine.
For Mac, Android Studio 3.6.1, I added this to .bash_profile
export PATH="~/Library/Android/sdk/platform-tools/platform-tools":$PATH
Or the alternative solution could be
Make sure you already install for android SDK. Usually it is located under
/Users/your-user-name/Library/Android/sdk
If the SDK is there then run this command. ./platform-tools/adb install your-apk-location
From there you can generate the APK file That's the only sample to check if adb
command is there
For some reason when installed Android Studio 3.6.1 the adb file was actually in $ANDROID_HOME/platform-tools/platform-tools. not sure if this is a bug with my installation or what but this fixed it for me.
For Mac Os the default shell has moved on to "zsh" from "bash" as of Mojave and later releases, so for all the Mac users I would suggest go with the creating ".zshrc" file. "adb" runs as it is intended to be. Thanks #slhck for your info.!
Follow steps below
Open bash_profile using open -e .bash_profile
write
export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
close bash_profile file
run source .bash_profile
Done run your adb command now !!
In some cases, you may need to run source .bash_profile every time you open cmd to run adb commands
It's working fine..
brew install android-sdk
Later on:
android update sdk --no-ui --filter 'platform-tools'

Categories

Resources