Android开发常用的40个ADB命令

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 &

[](https://blog.csdn.ne外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

资料获取→专栏
t/zhoumushui/article/details/101175912)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 包名/类的全名

[](https://blog.cs

dn.net/zhoumushui/article/details/101175912)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 reboot -p


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

34.安装app

adb install <path_to_apk>

35.文件复制

4.1从手机拉到本地

adb pull

例如:

adb pull /sdcard/foo.txt foo.txt

4.2从本地推到手机

adb push

例如:

adb push foo.txt /sdcard/foo.txt

36.卸载软件

15 install hello.apk

34.安装app

adb install <path_to_apk>

35.文件复制

4.1从手机拉到本地

adb pull

例如:

adb pull /sdcard/foo.txt foo.txt

4.2从本地推到手机

adb push

例如:

adb push foo.txt /sdcard/foo.txt

36.卸载软件

  • 26
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值