ADB
ADB (Android Debug Bridge) Master ADB commands for Android device communication and debugging
Android Tools Quest #16 Intermediate

ADB (Android Debug Bridge)

Master ADB commands for Android device communication and debugging

androidadbdebuggingmobiletesting
Download as:

What is ADB?

Android Debug Bridge (ADB) is a versatile command-line tool that enables communication with Android devices. It’s essential for Android development, testing, and automation.

ADB is automatically used by Appium when running tests on Android devices.

Prerequisites

ADB is included with the Android SDK Platform-Tools.

Verify Your Installation

adb version

If not found, add to your PATH:

export PATH=$PATH:$ANDROID_HOME/platform-tools

Device Connection

List Connected Devices

adb devices

Output states:

  • device - Connected and authorized
  • unauthorized - Need to accept debugging prompt on device
  • offline - Device not responding

Connect Over Wi-Fi

  1. Connect device via USB first:

    adb tcpip 5555
  2. Disconnect USB and connect over Wi-Fi:

    adb connect DEVICE_IP:5555
  3. To disconnect:

    adb disconnect DEVICE_IP:5555

Target Specific Device

When multiple devices are connected:

adb -s DEVICE_SERIAL shell

App Management

Install an APK

adb install app.apk

# Replace existing app
adb install -r app.apk

# Install on SD card
adb install -s app.apk

Note: The -s flag is deprecated and unsupported on Android 9+ (API 28+). Most modern devices ignore it. On newer devices, omit the flag entirely or use adb push to transfer the APK and install it manually.

Uninstall an App

adb uninstall com.example.app

# Keep data and cache
adb uninstall -k com.example.app

List Installed Packages

# All packages
adb shell pm list packages

# Filter by name
adb shell pm list packages | grep example

# Third-party apps only
adb shell pm list packages -3

Clear App Data

adb shell pm clear com.example.app

Force Stop App

adb shell am force-stop com.example.app

File Transfer

Push to Device

adb push local_file.txt /sdcard/
adb push local_folder /sdcard/

Pull from Device

adb pull /sdcard/remote_file.txt ./
adb pull /sdcard/remote_folder ./

Shell Commands

Interactive Shell

adb shell

Single Command

adb shell ls /sdcard/

Run as Root (if available)

adb root
adb shell

Common Shell Commands

# List files
adb shell ls -la /sdcard/

# Check disk space
adb shell df -h

# Running processes
adb shell ps

# Device info
adb shell getprop ro.product.model
adb shell getprop ro.build.version.release

Screen Capture

Screenshot

adb shell screencap /sdcard/screen.png
adb pull /sdcard/screen.png

One-liner

adb exec-out screencap -p > screen.png

Screen Recording

# Start recording (max 3 minutes)
adb shell screenrecord /sdcard/video.mp4

# Stop with Ctrl+C, then pull
adb pull /sdcard/video.mp4

Logging

View Logs

adb logcat

Filter by Priority

# Verbose, Debug, Info, Warning, Error, Fatal
adb logcat *:E  # Errors only
adb logcat *:W  # Warnings and above

Filter by Tag

adb logcat -s MyAppTag

Clear Logs

adb logcat -c

Save to File

adb logcat > log.txt

Intent Commands

Start an Activity

adb shell am start -n com.example.app/.MainActivity

Start with Action

adb shell am start -a android.intent.action.VIEW -d "https://example.com"

Send Broadcast

adb shell am broadcast -a com.example.CUSTOM_ACTION

Input Simulation

Tap Screen

adb shell input tap 500 500

Swipe

adb shell input swipe 100 500 400 500  # Left to right

Type Text

adb shell input text "Hello"

Key Events

adb shell input keyevent KEYCODE_HOME
adb shell input keyevent KEYCODE_BACK
adb shell input keyevent KEYCODE_ENTER

Troubleshooting

Restart ADB Server

adb kill-server
adb start-server

Device Unauthorized

  1. Check device for authorization prompt
  2. Revoke authorizations: Settings > Developer options > Revoke USB debugging
  3. Reconnect device

Device Offline

adb kill-server
adb start-server
adb devices

Multiple Devices

Always specify device:

adb -s emulator-5554 shell
adb -s DEVICE_SERIAL install app.apk

Resources

πŸ”—
ADB Documentation developer.android.com

Official Android Debug Bridge documentation

πŸ”—
ADB Command Reference adbshell.com

Comprehensive ADB command cheat sheet