您的位置:首页 > 其它

国外的开发者对于adb调试的总结(英语很好懂,不翻译了)

2014-05-16 12:14 387 查看

View connected device(s)

Use this to view all connected devices and list their IDs.
adb devices
If multiple devices are attached, use
adb -s DEVICE_ID
to target a specific device.

Install an application

Use the
install
command to install an apk, the optional
-r
argument reinstalls and keeps any data if the application is already installed on the device.
adb install -r APK_FILE

# example
adb install -r ~/application.apk

Uninstall an application

adb uninstall PACKAGE_NAME

# example
adb uninstall com.growingwiththeweb.example

Start an activity

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

Entering the device’s shell

adb shell

Take a screenshot

Sergei Shvetsov came up with a nice one liner that takes a screenshot with
shell
 screencap
and outputs it to a local directory using perl. Checkout his blog for an explanation.
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png

Power button

This command sends the power button event to turn the device on or off.
adb shell input keyevent 26

Unlock screen

This command sends the event that unlocks the lockscreen on the device. It can be combine with the power button command above to turn on and unlock the device.
adb shell input keyevent 82

Print all installed packages

adb shell pm list packages -f

Logging

To show the log stream on your command line.
adb logcat

Filter by tagname

adb logcat -s TAG_NAME
adb logcat -s TAG_NAME_1 TAG_NAME_2

#example
adb logcat -s TEST
adb logcat -s TEST MYAPP

Filter by priority

To show logs of a specific priority warning and above.
adb logcat "*:PRIORITY"

# example
adb logcat "*:W"
Here are the priority levels:
V
- Verbose (lowest priority)
D
- Debug
I
- Info
W
- Warning
E
- Error
F
- Fatal
S
- Silent (highest priority, on which nothing is ever printed)

Filter by tagname and priority

adb logcat -s TAG_NAME:PRIORITY
adb logcat -s TAG_NAME_1:PRIORITY TAG_NAME_2:PRIORITY

#example
adb logcat -s TEST: W

Filter using
grep

Alternatively the output of
logcat
can be piped to
grep
on a system that supports it.
adb logcat | grep "SEARCH_TERM"
adb logcat | grep "SEARCH_TERM_1\|SEARCH_TERM_2"

#example
adb logcat | grep "Exception"
adb logcat | grep "Exception\|Error"

Clearing the
logcat
buffer

Use this to clear the buffer to remove any old log data.
adb logcat -c
下面是中文翻译版:
下面是一些我搜集的一些Android ADB(Android Debug Bridge)命令,在手动或自动构建和测试过程中它们非常好用。

查看已连接的设备

使用此命令查看所有的连接设备,并列出它们的ID:
如果存在多个设备连接,可以使用
adb -s DEVICE_ID
来指定特定的设备。

安装应用

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

卸载应用

启动Activity

进入设备的命令行

截取屏幕Sergei Shvetsov 写出了一行漂亮的PERL代码,它利用 shell screencap截屏并输出到本地目录中,访问他的博客获取详细信息。
解锁屏幕向设备发送屏幕解锁命令:

日志

用来在命令行中显示日志流:
按标签名过滤
按优先级过滤显示指定告警优先级及以上的日志:
优先级设置如下:V:Verbose (最低优先级)D:DebugI:InfoW:WarningE:ErrorF:FatalS:Silent (最高优先级, 在这个级别上不会打印任何信息))按标签名和优先级过滤
使用grep过滤另外,在支持
grep
的系统中,
logcat
输出可以通过管道发送给
grep
清除logcat的缓冲区使用这个命令来清除缓冲区,并清除旧的日志数据:
[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: