After you download Android Studio and install the SDK, if you want to do something like start Firebase debug mode, the tutorial might tell you to type “adb” on the terminal. If you do, the following might appear:
Command not found: adbCopy the code
Or:
adb : The term 'adb' is not recognized as the name of a cmdlet, function, script file, or operable program.
Copy the code
(ADB: The "ADB" entry cannot be recognized as the name of a cmdlet, function, script file, or runnable program)Copy the code
If you subconsciously search for “how to install ADB,” you’ll probably end up with instructions for installing it through your operating system’s package-management tool or by downloading a zip file from a mobile customization site. But none of this is necessary! Adb is installed when you install the Android SDK using Android Studio, and with just a few manual steps, you can ensure that you always use the same up-to-date tools as your IDE!
What does adb care?
Adb stands for “Android Debug Bridge “, it is a multi-functional command line debugging tool for the Android platform. Normally, it will be installed when you install the Android SDK using platform-tools in Android Studio, but there are some Settings you need to make if you want the operating system to know where ADB is.
First, open Android Studio and navigate to “Tools > SDK Manager” from the menu:
△ Tools > SDK Manager in Android Studio
At the top of the window, you can see the path where the IDE installed the Android SDK.
Now open your terminal, type CD and paste the path. You can do this on Windows, macOS, and Linux, but on Windows you may need to press Shift + Insert to paste the path into the terminal:
Next type CD platform-tools:
Then type ls (dir in Windows). You should be able to see ADB or adB.exe — depending on your operating system. You can then type./adb and view the program output.
You can now run ADB, but I haven’t seen a tutorial that starts with “Copy your SDK path, use CD to go to the platform-tools folder, and type./ before ADB.” To get an experience that more Android developers like, you must update the PATH environment variable. The Settings vary from operating system to operating system, but I’ll list them on macOS and Windows below. On Linux, the steps may be different, but the instructions for macOS apply in some cases as well.
MacOS configuration
MacOS (and Linux) users typically use ZSH or bash for their shells. To temporarily add the platform-tools directory to PATH, type:
PATH="<path from the SDK manager>/platform-tools:$PATH"
Copy the code
Combined with the previous examples:
PATH="/Users/martinpatrick/Library/Android/sdk/platform-tools:$PATH"
Copy the code
The current terminal window is now ready to type ADB and execute commands at any time. But how to keep it that way?
Since Android Studio tends to install the Android SDK in your user directory, you need to edit the PATH for the user. And because it’s a command-line program, you just need to update the PATH for the terminal (Mac applications don’t use this). To do this, you need to edit the.profile file in your home directory (if that file doesn’t exist, you can get similar results using.bash_rc). This file is hidden by default, so you may not see it in the Finder. You can open this file in your favorite text editor:
nano ~/.profile
Copy the code
And at the end of the file add:
export ANDROID_SDK_ROOT="<your Android SDK path>"
Copy the code
export PATH="$ANDROID_SDK_ROOT/platform-tools:$PATH"
Copy the code
Here it is on my computer:
export ANDROID_SDK_ROOT="/Users/martinpatrick/Library/Android/sdk"
Copy the code
export PATH="$ANDROID_SDK_ROOT/platform-tools:$PATH"
Copy the code
Adding additional ANDROID_SDK_ROOT declarations is not necessary, but it might be useful for some of the more complex advanced user tools, such as the Cocos 2D command line program.
This way, when you open a new terminal window and type ADB, if you have done all the steps correctly, you will see a help page that lists the uses of ADB.
Windows configuration
Windows is a little different, and I’ll work entirely in PowerShell. As before, I can use the SDK manager to find where the SDK is installed:
And I can also change the directory to find my platform-tools:
To update PATH in PowerShell, type:
$env:PATH += "; <your Android SDK directory>\platform-tools"Copy the code
The specific command in this example is:
$env:PATH += "; C:\Users\pux19\AppData\Local\Android\Sdk\platform-tools"Copy the code
To keep this PATH variable in multiple terminal Windows (including, of course, the regular cmD.exe prompt if you need it), we can set this variable for the user in the GUI tool.
The easiest way to change this setting is to click on the Windows menu and search “Edit the System Environment variables “(I usually search” Environment variables “):
Then click “Environment Variables “:
Double-click “Path” in the “User Variables “section:
Then, click on a new cell and paste the path to your platform-tools directory into the cell:
In this case, it is C:\Users\pux19\AppData\Local\Android\Sdk\platform-tools
After clicking OK on all the Windows that open, the new terminal window will respond to ADB commands as you type. Microsoft generally recommends logging out and logging in again to preserve this state, but this is not absolutely necessary unless you need to use PATH in your GUI programs.
conclusion
This way, you can freely manage and debug your phone, tablet, and even set-top box from the command line. Also note that many of the tools are installed with their own SDK, and simply follow the same steps and make a few minor modifications to make any Android SDK your “default” tool. Keep in mind that only one PATH can be added to PATH at a time. If you decide to uninstall development tools (or even Android Studio), you’ll have to update these paths manually.