1, adb basic commands
1.1 Basic
- View adb version: Check the configuration and use adb information about the version
adb version
- View connected devices: Check the device using links
adb devices
- Remote Control & Exit Control Equipment: View device files
adb shell
exit
- Link device
adb connect [<host>[:<port>]](默认端口号是:5555)
- Execute remote shell command
adb shell <command>
- Copy the file to the device:
adb push <local> <remote>
- Copy the files from the device:
adb pull <remote> [<local>]
- View all devices:
adb bugreport #包括 bug 报告
- View command help:
adb help
1.2, apk related
- Install apk file
adb install <file>
- Uninstall app
# 参数-k 可选,用作卸载软件但保留配置文件和缓存
adb uninstall -k <package>
- View app all relevant information (including information action, codepath, verion, etc. need permission)
adb adb shell dumpsys package <package_name>
- View app path
adb shell pm path <package_name>
- View apk version information
adb shell dumpsys package <package_name> |grepversion
2, advanced command
2.1, adb logcat related
- View Log
adb logcat
- Save Log
adb logcat > <file>
- From the beginning of the current display
#logcat有缓存,先清空之前的再查看log即从当前开始显示
adb logcat -c && adb logcat
- grep filtration, using the same pipe command linux
adb logcat |grep MyLog #不忽略大小写
adb logcat |grep -i Mylog #忽略大小写
- Filter tag name
adb logcat -s <TAG_NAME>
adb logcat -s <TAG_NAME_1> <TAG_NAME_2>
- Log priority
priority | Explanation |
---|---|
V | Rule (lowest priority) |
D | debugging |
I | information |
W | caveat |
E | error |
F | fatal |
S | Silent (highest priority, will not print any information) |
- Clear Log fast
adb logcat -c
2.2, service-related
- Adb start & terminate service
adb start-server
adb kill-server
- Restart adb as root
adb root
- The system partition is re-writable hanging partition (This command is very important when operating system directory)
adb remount
- Reboot (optional)
adb reboot [brootloader] # 刷机模式
adb reboot [recovery] # 恢复模式
- Memory usage of each process in detail ways to view memory usage and system
# Total PSS信息是应用真正占内存的大小,通过这个信息可以判断手机中那些程序占内存比较大
adb shell dumpsys meminfo
# 部分设备支持
# VSS -virtual Size虚拟好用内存(包括功效库占用内存)
# RSS -Resident Set Size 实际使用武力内存(包含共享库占用内存)
# PSS -proportianal Set Size 实际使用武力内存(比例分配共享库占用的内存)
# USS -Unique Set Size 进程独自占用的武力内存(不包含共享库占用的内存)
adb shell procrank
# 查看设备上进程的CPU和内存占用情况
adb shell top
- View alarm system settings
adb shell dumpsys alarm
- View system Wakelock: wakelock unreasonable use can lead to increased system power consumption
adb shell dumpsys power
2.3, apk related
- Start activity
adb shell dumpsys window | findstr mCurentFocus #查看当前运行的报名和Activity
adb shell am start -n <package_name>/<activity_class_name>
- Clear Package Dependencies
adb shell pm clear <package> # 清除应用数据、删除与包相关的所有数据:清楚数据缓存
- Obtain application start time: returns the result WaitTime subject returned to the application is the time from the first frame startActivity fully displayed.
adb sell am start -W <package_name>/<activity_class_name>
- Start server
# 参数-n 表示组件
# 参数-a 表示命令,后面参数为mainfrest中定义的sevice的action
adb shell am startservice -n <package_name>/<service_class_name>
# 举例
adb shell am startservice -a "android.intent.action.CALL"
- Send broadcast
# 参数-es 为String 参数类型
# 参数-ei 为int 参数类型
# 参数-ez 为boolean参数类型
adb shell am broadcast -a"android.intent.action.AdupsFata.WriteCommandReceiver"
- View an app's process-related information
# 两种方式分别在部分手机可用
adb shell ps <package_name|PID>
adb shell ps | grep <package_name>
- Kill a process: a simulation language bug reproducibility
adb shell kill pid Number
- View an app's memory footprint
# Heap size包括了Dalvik Heap和Native Heap
adb shell dumpsys meminfo <package_name|PID>
- Check the maximum memory limit of a single application
# 如果得到结果小于Dalvik Heap size,就很可能发生OOM
adb shell dumpsys memin
- Gets a single application of power consumption information
# Android5.0引入,可获得系统耗电信息原始数据
adb shell dumpsys batterystats > <pacage_name> > xx.txt
# 科通过google编写的histian.py,转化为列表数据
python historian.py xx.txt >xx.html
System-related
- Check the device name (device name is to get a third-party app by this method)
adb shell cat /system/build.prop/
- View phone resolution
# 方法1:使用grep过滤
adb shell dumpsys window | grep surface
# 方法2:直接查询
adb shell wmsize
- View phone model information
adb shell cat /system/build.prop/
- View phone model information
# product,brand,CPU等型号信息
adb shell getprop | grep product
- Obtain the serial number: serial number that is listed adb devices
adb get-serialno
- Connecting a plurality of devices, wherein a device operating
# 参数 -d 真机(多个设备中只有一个真机时使用)
# 参数 -s 序列号
# 参数 -e 模拟器(多个设备中只有一个是虚拟机时使用)
adb [-d|-e|-s <serial Number> ] <command>
- View wifi password (requires root privileges)
adb shell cat data/misc/wifi/*.conf
- View wifi mac address
adb shell cat /sys/chlass/net/wlan0/address
- View background information services
adb shell service list
10. Check the system memory usage
adb shell cat /proc/meminfo
File-related operations (basic operations with linux)
- Copy the file / directory to the device
adb push <local> <remote>
- Copy files from the device / directory
# 参数 -a 保留了文件的时间戳和模式
adb pull [-a] <remote> <local>
- View device log
# 同Android Studio/Eclipse的logcat
# 参数 -s 过滤置顶参数log
# 参数 -v time 保留日志时间
# >>追加写,>覆盖写
adb logcat
- Files in the directory are listed
# 参数 -al 可选,可查看文件和文件夹的详细信息
adb shell ls [-al]
- Into the folder
adb shell ce <folder>
- check the file
adb shell cat <filename>
- Rename the file
adb shell rename <file> <file>
- Delete files / folders
# 参数 -r 可选,同linux操作含义
adb shell rm path/filename -r
- Moving Files
adb shell mv <源文件> <目标文件>
- Copy files
adb shell cp <源文件> <目标文件>
- Create a directory
adb shell mkdir <目录>
- Setting up file read and write permissions
adb shell chmod 777 <file>
- Not root the phone app to view certain file information
# 没有权限查看/data/data目录下的文件,运行后则可进入你的App下,再通过cp或者mv把需要的文件放在sdcard中进行操作
run -as package_name
- Database-related actions
# 无需将数据库pull出来再看,可直接查看db中的某个表或者字段
sqlit3 test.db
Monkey (subsequent supplementary detail)
adb shell monkey -v -p <package_name> 500
# -p 对象包 -v 反馈信息级别
# :Monkey: seed=1493061025112 count=500 :AllowPackage:com.tencent.mm.app:push :IncludeCategory: android.intent.category.LAUNCHER:IncludeCategory: android.intent.category.MONKEY ** No activities found to run,monkey aborted.
Adb install
mac
brew cask install android-platform-tools
Content scenarios:
- No code permission, under conditions no black box development environment conditions, easy to view log
- automated test
- jeckens integration tests use
- Mobile Remote Access