Android ADB常用命令

来源:互联网 发布:淘宝lol封号可以解封吗 编辑:程序博客网 时间:2024/05/22 05:32

                                                                        Android ADB常用命令

1.查看已连接的设备

使用此命令查看所有的连接设备,并列出它们的ID:

1
adb devices

如果存在多个设备连接,可以使用 adb -s DEVICE_ID 来指定特定的设备。

2.安装应用

使用 install 命令来安装apk,如果设备上已经安装了应用,可以使用可选参数 -r 重新进行安装并保留所有数据。

1
2
3
4
adbinstall-r APK_FILE
 
# example
adbinstall-r com.growingwiththeweb.example

3.卸载应用

1
2
3
4
adb uninstall PACKAGE_NAME
 
# example
adb uninstall com.growingwiththeweb.example

4.启动Activity

1
2
3
4
5
6
adb shell am start PACKAGE_NAME/ACTIVITY_IN_PACKAGE
adb shell am start PACKAGE_NAME/FULLY_QUALIFIED_ACTIVITY
 
# example
adb shell am start -n com.growingwiththeweb.example/.MainActivity
adb shell am start -n com.growingwiththeweb.example/com.growingwiththeweb.example.MainActivity

5.进入设备的命令行

1
adb shell

6.截取屏幕

Sergei Shvetsov 写出了一行漂亮的PERL代码,它利用 shell screencap截屏并输出到本地目录中,访问他的博客获取详细信息。

1
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g'> screen.png

解锁屏幕
向设备发送屏幕解锁命令:

1
adb shell input keyevent 82

7.日志

用来在命令行中显示日志流:

1
adb logcat

按标签名过滤

1
2
3
4
5
6
adb logcat -s TAG_NAME
adb logcat -s TAG_NAME_1 TAG_NAME_2
 
# example
adb logcat -s TEST
adb logcat -s TEST MYAPP

按优先级过滤
显示指定告警优先级及以上的日志:

1
2
3
4
adb logcat "*:PRIORITY"
 
# example
adb logcat "*:W"

优先级设置如下:

  • V:Verbose (最低优先级)
  • D:Debug
  • I:Info
  • W:Warning
  • E:Error
  • F:Fatal
  • S:Silent (最高优先级, 在这个级别上不会打印任何信息))

按标签名和优先级过滤

1
2
3
4
adb logcat -s TAG_NAME:PRIORITY 
adb logcat -s TAG_NAME_1:PRIORITY TAG_NAME_2:PRIORITY`
# example 
adb logcat -s TEST: W

使用grep过滤
另外,在支持grep的系统中,logcat输出可以通过管道发送给grep

1
2
3
4
5
6
adb logcat | grep"SEARCH_TERM"
adb logcat | grep"SEARCH_TERM_1\|SEARCH_TERM_2"
 
# example
adb logcat | grep"Exception"
adb logcat | grep"Exception\|Error"

清除logcat的缓冲区
使用这个命令来清除缓冲区,并清除旧的日志数据:

1
adb logcat -c


感觉不错,就转了!大家学习下吧!
0 0