Basics

Introduction

adb talks to an Android device over USB or Wi-Fi. This sheet targets platform-tools 37.

Devices

CommandDescription
adb devicesList connected devices
adb devices -lList with model and product
adb get-statePrint offline/bootloader/device
adb wait-for-deviceBlock until a device connects
adb -s SERIAL <cmd>Target one device
adb -e <cmd>Target the emulator
adb -d <cmd>Target the only USB device
adb start-serverStart the adb server
adb kill-serverStop the adb server
adb server-statusShow server diagnostics

$ANDROID_SERIAL sets the default target; -s overrides it.

See: adb documentation

Wireless debugging

adb pair 192.168.1.20:37123     # code from the pairing dialog
adb connect 192.168.1.20:5555   # wireless debugging port
adb disconnect 192.168.1.20:5555
adb tcpip 5555                  # Android 10 and lower, after USB

pair uses the port shown in the pairing dialog; connect uses the wireless debugging port. adb mdns services discovers devices on the network.

See: Connect over Wi-Fi

Installing apps

adb install app.apk
adb install -r app.apk          # replace, keep data
adb install -g app.apk          # grant runtime permissions
adb install-multiple a.apk b.apk
adb uninstall com.example.app
adb uninstall -k com.example.app  # keep data

Install options

OptionDescription
-rReplace an existing app
-tAllow test packages
-dAllow a version downgrade
-gGrant all runtime permissions
--abiOverride the device ABI

See: Package manager

Files and shell

File transfer

adb push local.txt /sdcard/local.txt
adb pull /sdcard/local.txt ./
adb pull -a /sdcard/DCIM ./photos  # keep timestamps
adb push --sync ./build /sdcard/build

adb sync copies a local AOSP build to the device.

See: Copy files

Remote shell

CommandDescription
adb shellInteractive shell
adb shell <command>Run one command
adb shell wm sizePrint screen resolution
adb shell wm size 1080x1920Override resolution
adb shell pm list packagesList installed packages
adb shell pm list packages -3Third-party packages only
adb exec-out screencap -p > a.pngRaw stdout, no pty

See: Issue shell commands

Quoting

adb shell setprop key "'two words'"

Arguments are passed like ssh, so quote twice for the device shell.

See: Issue shell commands

Port forwarding

adb forward tcp:6100 tcp:7100  # host port → device port
adb forward --list
adb reverse tcp:8080 tcp:8080  # device port → host port
adb reverse --list

Use reverse to point an app at a server running on the workstation.

See: Port forwarding

Debugging

Logcat

CommandDescription
adb logcatStream log messages
adb logcat -dDump the buffers and exit
adb logcat -cClear the buffers
adb logcat -gShow buffer sizes
adb logcat -G 16MSet the buffer size
adb logcat -s MyTagFilter to one tag
adb logcat *:EErrors only
adb logcat -f out.logWrite to a file

See: Logcat

Screenshots and recordings

adb exec-out screencap -p > screen.png
adb shell screenrecord /sdcard/demo.mp4
adb pull /sdcard/demo.mp4

screenrecord takes --time-limit (max 180) and --bit-rate.

See: Take a screenshot

Dumps and bug reports

CommandDescription
adb bugreport report.zipFull bug report
adb shell dumpsys activityActivity state
adb shell dumpsys meminfo <pkg>Memory use
adb shell dumpsys gfxinfo <pkg>Frame stats
adb shell dumpsys batteryBattery state
adb jdwpDebuggable PIDs

See: Bug reports

Device control

Activities and input

CommandDescription
adb shell am start -n com.example/.MainActivityStart an activity
adb shell am start -a android.intent.action.VIEWSend a VIEW intent
adb shell am force-stop com.exampleStop the app
adb shell monkey -p com.example 1Launch the app
adb shell input tap 500 800Tap a coordinate
adb shell input text 'hello'Type text
adb shell input keyevent 26Send a key event

Add -d https://example.com to open a URL with the VIEW intent.

See: Activity manager

Power and system

CommandDescription
adb rebootReboot
adb reboot bootloaderReboot to the bootloader
adb reboot recoveryReboot to recovery
adb sideload ota.zipSideload an OTA package
adb root / adb unrootRestart adbd with/without root
adb remountRemount partitions read-write
adb disable-verityDisable dm-verity (userdebug)
adb shell cmd testharness enableReset a test device

See: Platform tools

Emulator console

adb emu kill    # stop the emulator
adb emu avd name

adb emu forwards a command to the emulator console of the target.

See: Emulator console

Also see

0 Comments for this cheatsheet. Write yours!