CPS251 Android Development by Scott Shaper

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

Step 1: Locate the ADB Tool

ADB is part of the Android SDK Platform-Tools, which can be installed via Android Studio.

  1. Open Android Studio and go to Tools > SDK Manager.
  2. Navigate to the SDK Tools tab in the SDK Manager.
  3. 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:

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:

  1. Open Terminal.
  2. Edit the shell profile file (.bash_profile, .zshrc, .bashrc, etc.) depending on which shell you use. For most macOS users, it's likely .zshrc on newer systems:
    vi ~/.zshrc
    
  3. Add the ADB tool to your PATH:
    export PATH=$PATH:/Users/$PATH/Library/Android/sdk/platform-tools
    
    Save and exit the editor (Ctrl + X, then Y to confirm changes, and Enter to exit).
  4. Apply the changes:
    source ~/.zshrc
    

For Windows:

  1. Search for Environment Variables in the Start menu.
  2. Select Edit the system environment variables > Environment Variables.
  3. Under System Variables, find and select the Path variable, then click Edit.
  4. Add a new entry for the path to the ADB tool:
    C:\Users\<Your-Username>\AppData\Local\Android\Sdk\platform-tools
    
  5. 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.