安卓的 adb 工具与命令行

Yifei’s Notes

adb is pretty unstable, it’s meant for debug usage, NOT for a long-running service.


install on ubuntu: apt-get install android-tools-adb android-tools-fastboot

install on mac: brew install android-platform-tools

Connect model

there is a server on PC called adb server, if not started, will be started on first adb client call commands. there is an adbd daemon on phone, run as not root by default.

adb devices

list all devices, give serial number for usb, and ip:port for wifi devices as adb id. if only one device, all commands are issued to that device, if many, use adb -s command to select a device.

Connect over Wifi

  1. first usb adb to the device
  2. second

if rooted and run this on phone

setprop service.adb.tcp.port 5555
stop adbd && start adbd

if not rooted and run this on computer

adb tcpip 5555
  1. adb connect ip:port
  2. adb usb # back to usb mode


adb pull phone_path pc_path
adb push pc_path phone_path


adb install 
adb uninstall
adb shell pm clear PACKAGE_NAME  # clears package data


adb forward local:port android:port
adb wait-for-device

adb forward host device
adb forward tcp:6100 tcp:7100


remounts the /system, /vendor (if present) and /oem (if present) partitions on the device read-write

get running activity name

adb shell dumpsys activity | grep mFocusedActivity


error closed

可能是权限不够,执行了 n 权限过高的操作,需要首先执行 adb root

能用 ssh,就用 ssh ,不要用 adb

Android Shell Command


32 bit adb 在 64 位 linux 上无法运行

The error message is no such file of directory, which is quite miss-leading

adb install 安装失败

apk 没有权限 应该 777
apk 有证书不一致的 卸载旧的 apk

Configuator 设置 uiautomator 的超时时间,参见 [1]


从手机上拉取已安装应用的 apk 文件

adb shell pm path com.example.someapp
adb pull /data/app/com.example.someapp-2.apk