Android 开发常用的 40 个 ADB 命令,总结拼多多美团 Android 面试经验
11.查看当前设备 DDR 运行频率
cat /proc/clocks | busybox grep “ddr”
12.ADB logcat 过滤
adb logcat -s TAG_NAME
adb logcat -s TAG_NAME_1 TAG_NAME_2
adb logcat “*:PRIORITY”
adb logcat -s TAG_NAME:PRIORITY
adb logcat -s TAG_NAME_1:PRIORITY_1 TAG_NAME_2:PRIORITY
优先级(PRIORITY)分为以下几种:
V – Verbose
D – Debug
I – Info
W – Warning
E – Error
F – Fatal
S – Silent
范例:
adb logcat *:E 查看异常信息
adb logcat -s “TAG” 过滤 TAG
013.查看设备是否拥有 su 权限(4.2 及之前版本)
adb shell
ps
会列出系统进程
选一个 u 开头的 表示普通程序
su u0_a8
#切换到 u0_a8 下 #号变 >
su
#如果可以执行,>号为 #号,则表示有 su 权限,如果提示权限问题,就没有 su 权限
14.查看应用引用
adb 查看 Android 应用所有引用
adb shell
ps (查看 PID 号)
cd /proc/PID 号/fd
busybox ls -l
也将文件拷贝出来
cat xxx > /sdcard/xxx
15.获取运行内存/CPU 信息
adb shell
cat /proc/meminfo
cat /proc/cpuinfo
16.抓取 Logcat 信息及 kmsg 信息
cat proc/kmsg >/data/kmsg.txt &
logcat -v time >/data/logcat.txt &
17.查看 Android(手机\平板\开发板等)设备信息
adb shell dumpsys package > package.xml
(此命令可显示手机(平板)可供应用查询到的 library 和 feature)
18.输出所有已经安装的应用
adb shell pm list packages -f
19.查看预安 apk
adb shell pm list packages -3
20.清除 logcat 缓冲区
(用这个命令来清除一些重复出现的过时的日志)
adb logcat -c
21.截取屏幕图片
截图直接保存到电脑
adb shell screencap -p | sed ‘s/\r//’ > screen.png
执行 adb shell 将\n 转换\r\n, 因此需要用 sed 删除多余的\r 如果直接当命令用还可以用 alias 包裝装起來
alias and-screencap=“adb shell screencap -p | sed ‘s/\r//’”
$ and-screencap > screen.png
以后就可以方便的用 and-screencap > 直接将截图保存到电脑上了其他入门级但也比较常见的 adb 命令 1、查看所有已经连接上的设备
adb devices
如果有多个设备连接到电脑,可以通过 adb -s DEVICE_ID 来指定用哪一个
22.挂载 system 分区(当然需要设备支持)
adb remount
23 安装与卸载应用
adb install <apk 文件路径>
adb install -r <apk 文件路径> 通过 install 命令来安装 apk 文件,-r 参数可以重新安装某个应用并保留应用数据
#举例
adb install -r ~/chrome.apk
卸载应用:
adb uninstall <软件名>
adb uninstall -k <软件名> 如果加 -k 参数,为卸载软件但是保留配置和缓存文件
#举例
adb uninstall com.android.chrome
24.启动一个 Activity
adb shell am start 包名/.类名
adb shell am start 包名/类的全名
25.登录设备 shell
adb shell --这个命令将登录设备的 shell.
adb shell <command 命令> 后面加<command 命令>将是直接运行设备命令, 相当于执行远程命令 6. 从电脑上发送文件到设备
–用 push 命令可以把本机电脑上的文件或者文件夹复制到设备(手机)
adb remount ## remount '/system’分区 as read-write
adb push <本地路径> <远程路径>7. 从设备上下载文件到电脑
–用 pull 命令可以把设备(手机)上的文件或者文件夹复制到本机电脑
adb pull <远程路径> <本地路径> 8. 显示帮助信息(包括各种命令用法与含义)
adb help
26.模拟功能按键
命令格式:adb shell sendevent [device] [type] [code] [value]
如: adb shell sendevent /dev/input/event0 1 229 1 代表按下按下 menu 键
adb shell sendevent /dev/input/event0 1 229 0 代表按下松开 menu 键
说明:上述的命令需组合使用
另外所知道的命令如下:
Key Name CODE
MENU 229
HOME 102
BACK (back button) 158
CALL (call button) 231
END (end call button) 107
2. 发送鼠标事件(Touch):
命令格式:adb shell sendevent [device] [type] [code] [value]
情况 1:在某坐标点上 touch
如在屏幕的 x 坐标为 40,y 坐标为 210 的点上 touch 一下,命令如下
adb shell sendevent /dev/input/event0 3 0 40
adb shell sendevent /dev/input/event0 3 1 210
adb shell sendevent /dev/input/event0 1 330 1 //touch
adb shell sendevent /dev/input/event0 0 0 0 //it must have
adb shell sendevent /dev/input/event0 1 330 0 //untouch
adb shell sendevent /dev/input/event0 0 0 0 //it must have
注:以上六组命令必须配合使用,缺一不可
情况 2:模拟滑动轨迹(可下载并采用 aPaint 软件进行试验)
如下例是在 aPaint 软件上画出一条开始于(100,200),止于(108,200)的水平直线
adb shell sendevent /dev/input/event0 3 0 100 //start from point (100,200)
adb shell sendevent /dev/input/event0 3 1 200
adb shell sendevent /dev/input/event0 1 330 1 //touch
adb shell sendevent /dev/input/event0 0 0 0
adb shell sendevent /dev/input/event0 3 0 101 //step to point (101,200)
adb shell sendevent /dev/input/event0 0 0 0
…………………… //must list each step, here just skip
adb shell sendevent /dev/input/event0 3 0 108 //end point(108,200)
adb shell sendevent /dev/input/event0 0 0 0
adb shell sendevent /dev/input/event0 1 330 0 //untouch
adb shell sendevent /dev/input/event0 0 0 0
27.设备的重启和关机
adb shell
shutdown
28.打开指定应用
adb shell am start -n com.android.dialer/com.android.dialer.DialtactsActivity
29.确认是哪个输入设备:
$ adb shell getevent
按键,看是哪个设备发出消息,这里假设是 event0
实测:
event0 按键
event3 屏幕
30.查看设备名称
$ adb shell cat /sys/class/input/event0/device/name
从而查处是调用的哪个 kl 文件。
31.模拟按键
shell@esky82_tb_cn_kk:/ $ input tap 280 1020
按下坐标为(280,1020)处的点
32.列举当前的设配:
adb devices
例如:
localhost:~ newuser$ adb devices
List of devices attached
BH903QDW15 device
41008990d29eb000 device
33.针对某一个设备进行
adb -s
例如:
adb -s BH903QDW15 install hello.apk
总结
其实客户端开发的知识点
《Android 学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
就那么多,面试问来问去还是那么点东西。所以面试没有其他的诀窍,只看你对这些知识点准备的充分程度。so,出去面试时先看看自己复习到了哪个阶段就好。


然而 Android 架构学习进阶是一条漫长而艰苦的道路,不能靠一时激情,更不是熬几天几夜就能学好的,必须养成平时努力学习的习惯。所以:贵在坚持!
评论