adb
Android Debug Bridge
https://developer.android.com/studio/command-line/adb.html
$ adb shell
$ am start -W -n
$ adb shell dumpsys meminfo <appPackage> #可以查看运行时app的占用内存情况
常用命令
说明
shell
获取编译时间
cat /proc/version
内核崩溃
cat /proc/last_kmsg
获取硬件信息
adb shell getprop ¦ grep cpu
获取序列号
adb get-serialno
查看连接计算机的设备
adb devices
查看模拟器/设施的当前状态
adb get-state
多设备下连接目标设备
adb -s xxx shell
重启机器
adb reboot
重启到bootloader,即刷机模式
adb reboot bootloader
重启到recovery,即恢复模式
adb reboot recovery
查看log
adb logcat
终止adb服务进程
adb kill-server
重启adb服务进程
adb start-server
查看Service列表
adb shell service list</br>adb shell dumpsys activity services
检查Service是否存在
adb shell service check phone
获取机器MAC地址
adb shell cat /sys/class/net/wlan0/address
获取CPU序列号
adb shell cat /proc/cpuinfo
安装APK
adb install //比如:adb install jiek.apk
保留数据和缓存文件,重新安装apk
adb install -r //比如:adb install -r jiek.apk
安装apk到sd卡
adb install -s // 比如:adb install -s jiek.apk
卸载APK
adb uninstall //比如:adb uninstall com.jiek.search
卸载app但保留数据和缓存文件
adb uninstall -k //比如:adb uninstall -k com.jiek.search
启动应用
adb shell am start -n /.
查看数据库
adb shell content query --uri content://settings/secure
查看设备cpu和内存占用情况
adb shell top
查看占用内存前6的app
adb shell top -m 6
刷新一次内存信息,然后返回
adb shell top -n 1
查询各进程内存使用情况
adb shell procrank
启动应用程序
adb shell am
杀死一个进程
adb shell kill [pid]
查看进程列表
adb shell ps
查看Android系统的属性
adb shell prop
查看指定进程状态
adb shell ps -x [PID]
查看后台services信息
adb shell service list
adb 查看最上层成activity名字
linux:adb shell dumpsys activity ¦ grep "mFocusedActivity"
windows:adb shell dumpsys activity ¦ findstr "mFocusedActivity"
查看当前内存占用
adb shell cat /proc/meminfo
查看IO内存分区
adb shell cat /proc/iomem
将system分区重新挂载为可读写分区
adb remount
从本地复制文件到设备
adb push
从设备复制文件到本地
adb pull
列出目录下的文件和文件夹,等同于dos中的dir命令
adb shell ls
进入文件夹,等同于dos中的cd 命令
adb shell cd
重命名文件
adb shell rename path/oldfilename path/newfilename
删除system/avi.apk
adb shell rm /system/avi.apk
删除文件夹及其下面所有文件
adb shell rm -r
移动文件
adb shell mv path/file newpath/file
设置文件权限
adb shell chmod 777 /system/fonts/DroidSansFallback.ttf
新建文件夹
adb shell mkdir path/foldelname
查看文件内容
adb shell cat
查看wifi密码
adb shell cat /data/misc/wifi/*.conf
清除log缓存
adb logcat -c
查看bug报告
adb bugreport
获取设备名称
adb shell cat /system/build.prop
查看ADB帮助
adb help
跑monkey
adb shell monkey -v -p your.package.name 500
dump堆栈
debuggerd -b
备份与恢复
备份:adb backup -f /Users/jiek/jiekBackup.ab -noapk com.jiek.search
恢复:adb restore "/Users/jiek/jiekBackup.ab"
拷贝文件
push从电脑端向手机复制文件: adb push /Users/jiek/tmp/test.txt /data/data/download/
;; pull从手机端向本地复制文件: adb pull /data/data/download/ /Users/jiek/tmp/
查看应用程序内存使用情况
adb shell dumpsys meminfo </br> 其中,package_name 也可以换成程序的pid, pid可以通过
adb shell top ¦ grep app_name` 来查找.
查看进程占用cpu的情况
adb shell top -n 1 -d 0.5 ¦ grep proc_ id
procrank查看内存占用
adb shell procrank `VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存)
RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存) PSS - Proportional Set Size 实际使用的物理内存(比例分配共享库占用的内存) USS - Unique Set Size 进程独自占用的物理内存(不包含共享库占用的内存)快速查看apk内androidmanifest文件内容| aapt dump xmltree xxxx.apk AndroidManifest.xml 列出一些系统信息和所有应用的信息| adb shell dumpsys packages > packages.log 列出一些指定应用的信息| adb shell dumpsys package com.jiek.search > tmp.txt 查看当前谁持有WAKE_LOCK锁对象| adb shell dumpsys power 查看电池用量详情| adb shell dumpsys batteryinfo 搜索文件| busybox find -name *xxx* 电池日志|
adb shell dumpsys batterystats > batterystats.txtbugreport日志| adb bugreport > bugreport.txt 电池日志图形界面查看| https://github.com/cacker/battery-historian 查看应用uid|
cat /proc//status`cat /data/system/packages.list ¦ grep xxx
cpu频率查看| cat [%cpuFreqPath%]/cpuinfo_cur_freq (当前cpu频率) `修改: echo xxx > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq (当前cpu频率) cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq (最大cpu频率) cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq (最小cpu频率) cat /sys/devices/system/cpu/cpu0/cpufreq/related_cpus (cpu数量标号,从0开始,如果是双核,结果为0,1) cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies (cpu所有可用频率) cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors (cpu所有可用调控模式) cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor (当前使用哪种调控模式) cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_transition_latency (变频延迟)某个应用内存消耗信息| adb shell dumpsys meminfo com.jiek.tmp > meminfo.txt zygote的堆栈dump| adb pull /data/anr/traces.txt trace.txt SYSTEM LOG| logcat -b system -v time -d *:v | grep sina.mobile
-b // 加载一个可使用的日志缓冲区供查看,比如event和radio,默认值是main. system // system log -v // 输出字段 time 显示时间 -d // 缓冲区日志打印并退出 *:v // 日志级别高到低 E W I D V grep sina.mobile // 过滤包含sina.mobile的信息 `
Manual手册
~ $ adb
Android Debug Bridge version 1.0.39
Revision 5943271ace17-android
global options:
-a listen on all network interfaces, not just localhost
-d use USB device (error if multiple devices connected)
-e use TCP/IP device (error if multiple TCP/IP devices available)
-s SERIAL
use device with given serial number (overrides $ANDROID_SERIAL)
-p PRODUCT
name or path ('angler'/'out/target/product/angler');
default $ANDROID_PRODUCT_OUT
-H name of adb server host [default=localhost]
-P port of adb server [default=5037]
-L SOCKET listen on given socket for adb server [default=tcp:localhost:5037]
general commands:
devices [-l] list connected devices (-l for long output)
help show this help message
version show version num
networking:
connect HOST[:PORT] connect to a device via TCP/IP [default port=5555]
disconnect [HOST[:PORT]]
disconnect from given TCP/IP device [default port=5555], or all
forward --list list all forward socket connections
forward [--no-rebind] LOCAL REMOTE
forward socket connection using:
tcp:<port> (<local> may be "tcp:0" to pick any open port)
localabstract:<unix domain socket name>
localreserved:<unix domain socket name>
localfilesystem:<unix domain socket name>
dev:<character device name>
jdwp:<process pid> (remote only)
forward --remove LOCAL remove specific forward socket connection
forward --remove-all remove all forward socket connections
ppp TTY [PARAMETER...] run PPP over USB
reverse --list list all reverse socket connections from device
reverse [--no-rebind] REMOTE LOCAL
reverse socket connection using:
tcp:<port> (<remote> may be "tcp:0" to pick any open port)
localabstract:<unix domain socket name>
localreserved:<unix domain socket name>
localfilesystem:<unix domain socket name>
reverse --remove REMOTE remove specific reverse socket connection
reverse --remove-all remove all reverse socket connections from device
file transfer:
push LOCAL... REMOTE
copy local files/directories to device
pull [-a] REMOTE... LOCAL
copy files/dirs from device
-a: preserve file timestamp and mode
sync [DIR]
copy all changed files to device; if DIR is "system", "vendor", "oem",
or "data", only sync that partition (default all)
-l: list but don't copy
shell:
shell [-e ESCAPE] [-n] [-Tt] [-x] [COMMAND...]
run remote shell command (interactive shell if no command given)
-e: choose escape character, or "none"; default '~'
-n: don't read from stdin
-T: disable PTY allocation
-t: force PTY allocation
-x: disable remote exit codes and stdout/stderr separation
emu COMMAND run emulator console command
app installation:
install [-lrtsdg] PACKAGE
install-multiple [-lrtsdpg] PACKAGE...
push package(s) to the device and install them
-l: forward lock application
-r: replace existing application
-t: allow test packages
-s: install application on sdcard
-d: allow version code downgrade (debuggable packages only)
-p: partial application install (install-multiple only)
-g: grant all runtime permissions
uninstall [-k] PACKAGE
remove this app package from the device
'-k': keep the data and cache directories
backup/restore:
backup [-f FILE] [-apk|-noapk] [-obb|-noobb] [-shared|-noshared] [-all] [-system|-nosystem] [PACKAGE...]
write an archive of the device's data to FILE [default=backup.adb]
package list optional if -all/-shared are supplied
-apk/-noapk: do/don't back up .apk files (default -noapk)
-obb/-noobb: do/don't back up .obb files (default -noobb)
-shared|-noshared: do/don't back up shared storage (default -noshared)
-all: back up all installed applications
-system|-nosystem: include system apps in -all (default -system)
restore FILE restore device contents from FILE
debugging:
bugreport [PATH]
write bugreport to given PATH [default=bugreport.zip];
if PATH is a directory, the bug report is saved in that directory.
devices that don't support zipped bug reports output to stdout.
jdwp list pids of processes hosting a JDWP transport
logcat show device log (logcat --help for more)
security:
disable-verity disable dm-verity checking on userdebug builds
enable-verity re-enable dm-verity checking on userdebug builds
keygen FILE
generate adb public/private key; private key stored in FILE,
public key stored in FILE.pub (existing files overwritten)
scripting:
wait-for[-TRANSPORT]-STATE
wait for device to be in the given state
State: device, recovery, sideload, or bootloader
Transport: usb, local, or any [default=any]
get-state print offline | bootloader | device
get-serialno print <serial-number>
get-devpath print <device-path>
remount
remount /system, /vendor, and /oem partitions read-write
reboot [bootloader|recovery|sideload|sideload-auto-reboot]
reboot the device; defaults to booting system image but
supports bootloader and recovery too. sideload reboots
into recovery and automatically starts sideload mode,
sideload-auto-reboot is the same but reboots after sideloading.
sideload OTAPACKAGE sideload the given full OTA package
root restart adbd with root permissions
unroot restart adbd without root permissions
usb restart adb server listening on USB
tcpip PORT restart adb server listening on TCP on PORT
internal debugging:
start-server ensure that there is a server running
kill-server kill the server if it is running
reconnect kick connection from host side to force reconnect
reconnect device kick connection from device side to force reconnect
environment variables:
$ADB_TRACE
comma-separated list of debug info to log:
all,adb,sockets,packets,rwx,usb,sync,sysdeps,transport,jdwp
$ADB_VENDOR_KEYS colon-separated list of keys (files or directories)
$ANDROID_SERIAL serial number to connect to (see -s)
$ANDROID_LOG_TAGS tags to be used by logcat (see logcat --help)
reference: http://blog.idhyt.com/2015/10/31/android-adb-shell-command/
Last updated
Was this helpful?