Set Up ADB
Setting up the Android Debug Bridge (ADB) command line tool is helpful for Android development as it allows you to communicate with an Android device or emulator instance. This tutorial will guide you through the process of setting up ADB for both macOS and Windows operating systems, including adding it to your system's environment variables for easy access from any command prompt.
You don't have to do this as it is not required for the class, but it may be needed for doing wireless connecting to your physical Android device if you decide to.
Prerequisites
- Android Studio installed: Ensure Android Studio is installed on your computer, as it includes the ADB tool.
- Access to terminal or command prompt: Depending on your OS, you'll need access to Terminal (macOS) or Command Prompt/PowerShell (Windows).
Step 1: Locate the ADB Tool
ADB is part of the Android SDK Platform-Tools, which can be installed via Android Studio.
- Open Android Studio and go to Tools > SDK Manager.
- Navigate to the SDK Tools tab in the SDK Manager.
- Check Android SDK Platform-Tools and click OK to install it if it's not already installed.
After installation, you'll need to locate the ADB tool:
- Default Path on Windows:
C:\Users\<Your-Username>\AppData\Local\Android\Sdk\platform-tools\ - Default Path on macOS:
/Users/$PATH/Library/Android/sdk/platform-tools/
Replace <Your-Username> with your actual username.
Step 2: Add ADB to Environment Variables
To use ADB from any terminal or command prompt, add its directory to your system's PATH environment variable.
For macOS:
- Open Terminal.
- Edit the shell profile file (
.bash_profile,.zshrc,.bashrc, etc.) depending on which shell you use. For most macOS users, it's likely.zshrcon newer systems:vi ~/.zshrc - Add the ADB tool to your PATH:
Save and exit the editor (export PATH=$PATH:/Users/$PATH/Library/Android/sdk/platform-toolsCtrl + X, thenYto confirm changes, andEnterto exit). - Apply the changes:
source ~/.zshrc
For Windows:
- Search for Environment Variables in the Start menu.
- Select Edit the system environment variables > Environment Variables.
- Under System Variables, find and select the
Pathvariable, then click Edit. - Add a new entry for the path to the ADB tool:
C:\Users\<Your-Username>\AppData\Local\Android\Sdk\platform-tools - Click OK to close all dialogs and apply the changes.
Step 3: Verify Installation
To ensure ADB is set up correctly, open a new Terminal or Command Prompt and type:
adb version
This command should display the version of ADB you have installed, indicating that it's correctly set up and accessible from the command line.
Below are some of the commands you can do with ADB
| Command | Description |
|---|---|
adb devices |
Lists all connected Android devices and emulators. |
adb install <apk-file> |
Installs the specified APK file on a connected device. |
adb uninstall <package-name> |
Uninstalls the specified app from a connected device. |
adb shell |
Opens a command-line shell on the connected device. |
adb logcat |
Streams system logs from the connected device, useful for debugging. |
adb push <local> <remote> |
Copies a file from the local system to the device. |
adb pull <remote> <local> |
Copies a file from the device to the local system. |
adb reboot |
Reboots the connected device. |
adb reboot bootloader |
Reboots the device into bootloader mode. |
adb forward <local> <remote> |
Forwards a local port to a remote port on the device. |
adb kill-server |
Stops the ADB server running on the host system. |
adb start-server |
Starts the ADB server on the host system. |
adb sideload <file.zip> |
Flashes a ZIP file (e.g., an OTA update) onto the device. |
Conclusion
You have now successfully set up the Android Debug Bridge (ADB) on both macOS and Windows, and added it to your PATH for easy access. This setup will allow you to perform a wide range of development tasks, including installing apps, scripting, and accessing the Android shell directly from your command line.