Using Android Debug Bridge (ADB) for App Development and Device Management

Last edited: August 4, 2025

Introduction

Android Debug Bridge (ADB) is a versatile command-line tool that lets you communicate with and control an Android device over a USB connection from your computer. Whether you’re a developer debugging applications, a power user managing your device, or someone who needs to recover data from a device with a broken screen, ADB is an essential tool in your Android toolkit.

What is ADB?

ADB is part of the Android SDK (Software Development Kit) and provides a variety of functions:

Setting Up ADB

Installation

On Windows:

  1. Download the Android SDK Platform Tools ZIP file
  2. Extract the ZIP file to an easily accessible location (e.g., C:\adb)
  3. Add the platform-tools directory to your system PATH:
    • Right-click on “This PC” and select “Properties”
    • Click on “Advanced system settings”
    • Click on “Environment Variables”
    • Under “System variables”, find and select “Path”, then click “Edit”
    • Click “New” and add the path to your platform-tools directory
    • Click “OK” to save

On macOS:

Using Homebrew:

brew install android-platform-tools

Or manual installation:

  1. Download the Android SDK Platform Tools ZIP file
  2. Extract to a location like ~/Library/Android/sdk/platform-tools
  3. Add to your PATH by adding this line to your ~/.bash_profile or ~/.zshrc:
    export PATH="$PATH:~/Library/Android/sdk/platform-tools"
    

On Linux:

Using apt (Debian/Ubuntu):

sudo apt update
sudo apt install adb

Using dnf (Fedora):

sudo dnf install android-tools

Enabling USB Debugging on Your Android Device

  1. Go to Settings > About phone
  2. Tap “Build number” seven times to enable Developer options
  3. Go back to Settings > System > Developer options
  4. Enable “USB debugging”
  5. Connect your device to your computer via USB
  6. Accept the “Allow USB debugging” prompt on your device

Verifying Installation

To check if ADB is properly installed and can detect your device:

adb devices

You should see your device listed with a serial number and “device” status.

Basic ADB Commands

Device Management

# List connected devices
adb devices

# Connect to a specific device when multiple are connected
adb -s DEVICE_SERIAL_NUMBER command

# Connect to a device over Wi-Fi
adb connect DEVICE_IP:5555

# Disconnect from a Wi-Fi device
adb disconnect DEVICE_IP:5555

# Reboot device
adb reboot

# Reboot to recovery mode
adb reboot recovery

# Reboot to bootloader
adb reboot bootloader

File Management

# Push a file to device
adb push /path/to/local/file /path/on/device

# Pull a file from device
adb pull /path/on/device /path/to/local/directory

# List files in a directory on device
adb shell ls /path/on/device

App Management

# Install an app
adb install path/to/app.apk

# Install app, replacing existing app
adb install -r path/to/app.apk

# Uninstall an app
adb uninstall com.example.app

# Uninstall app but keep data and cache
adb uninstall -k com.example.app

# Clear app data
adb shell pm clear com.example.app

# List all installed packages
adb shell pm list packages

# List only third-party packages
adb shell pm list packages -3

Debugging

# View device log
adb logcat

# Filter logcat by tag
adb logcat -s TAG_NAME

# Clear logcat buffer
adb logcat -c

# Dump system information
adb shell dumpsys

# Dump specific service information
adb shell dumpsys battery

Advanced ADB Usage

Shell Commands

ADB shell gives you access to a Unix shell running on the device:

# Enter interactive shell
adb shell

# Run a shell command directly
adb shell command

Common shell commands:

# View running processes
adb shell ps

# Check memory usage
adb shell dumpsys meminfo

# View CPU info
adb shell cat /proc/cpuinfo

# Check battery stats
adb shell dumpsys battery

# List all permissions
adb shell pm list permissions

# Grant a permission
adb shell pm grant com.example.app android.permission.CAMERA

# Revoke a permission
adb shell pm revoke com.example.app android.permission.CAMERA

Screen Capture

# Take a screenshot
adb shell screencap /sdcard/screenshot.png
adb pull /sdcard/screenshot.png

# Record screen (Android 4.4+)
adb shell screenrecord /sdcard/video.mp4
# Press Ctrl+C to stop recording
adb pull /sdcard/video.mp4

Backup and Restore

# Create a full backup
adb backup -apk -shared -all -f backup.ab

# Restore from backup
adb restore backup.ab

# Backup a specific app
adb backup -apk -f app_backup.ab com.example.app

Wireless Debugging

Connect your device via USB first, then:

# Make sure device and computer are on same network
adb tcpip 5555

# Disconnect USB and connect wirelessly
adb connect DEVICE_IP:5555

# To switch back to USB mode
adb usb

Practical Examples

Transferring Files When Screen is Broken

If your device screen is broken but the device still works:

# Enable USB debugging via ADB (if not already enabled)
adb shell settings put global adb_enabled 1

# Pull your photos
adb pull /sdcard/DCIM/Camera /path/on/computer

# Pull your documents
adb pull /sdcard/Documents /path/on/computer

Automating App Testing

# Install app
adb install app.apk

# Start an activity
adb shell am start -n com.example.app/.MainActivity

# Send keyevents
adb shell input keyevent KEYCODE_HOME

# Tap on screen
adb shell input tap X Y

# Swipe on screen
adb shell input swipe X1 Y1 X2 Y2 DURATION_MS

Fixing Common Issues

# Force stop an app
adb shell am force-stop com.example.app

# Clear app cache
adb shell pm clear com.example.app

# Reset app permissions
adb shell pm reset-permissions

Troubleshooting ADB

Device Not Detected

  1. Ensure USB debugging is enabled
  2. Try different USB cables and ports
  3. Install/update device drivers
  4. Restart ADB server:
    adb kill-server
    adb start-server
    

Permission Denied Errors

On Linux/macOS:

sudo adb kill-server
sudo adb start-server

Connection Refused

For wireless connections:

  1. Ensure device and computer are on same network
  2. Check firewall settings
  3. Reconnect via USB and restart wireless connection

Conclusion

ADB is a powerful tool that gives you unprecedented control over your Android device. While it may seem intimidating at first, mastering even a few basic commands can significantly enhance your ability to develop, test, and manage Android devices. As you become more comfortable with ADB, you’ll discover even more ways to leverage its capabilities for your specific needs.

Further Resources