转载请注明出处:http://blog.csdn.net/zhangyang0402/article/details/13095637
一、常用adb命令
1.查看设备$ adb devices
List of devices attached
emulator-5554 device
6651084d70b674 device
2. 连接特定设备
-d 连接的device,只能有一个,否则会报错
-e 连接的模拟器,只能有一个,否则报错
-s 指定特定的设备或模拟器
3. 进入设备的shell
$ adb -d shell
$ adb -e shell
4. 安装/卸载apk
$ adb -e install ~/Downloads/apk/_b_9.5.101.apk
2658 KB/s (3803627 bytes in 1.397s)
pkg: /data/local/tmp/_b_9.5.101.apk
Success
卸载应用程序
$ adb uninstall app_name
安装的应用程序在/data/data/目录下,可在目录下直接查看app_name,或通过下面的方法。
app_name是在AndroidManifest.xml中<manifest>节点下,package元素所指定的名字
将原来apk解压得到的AndroidManifest.xml,打开是乱码,需要使用apktool反编译得到AndroidManifest.xml,才能打开正常看。
$ apktool d ~/Downloads/apk/_b_9.5.101.apk
在当前目录下得到_b_9.5.101目录
查找app安装好后的名字
$ cat _b_9.5.101/AndroidManifest.xml |grep manifest
<manifest android:versionCode="1101" android:versionName="9.5.101" android:installLocation="auto" package="cn.chinabus.main"
</manifest>
$ adb uninstall cn.chinabus.main
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
Success
5. 传输文件(push/pull)
$ adb pull /init.rc ~/Downloads/
533 KB/s (24001 bytes in 0.043s)
$ adb push ~/Downloads/adb_usb.ini /data
0 KB/s (7 bytes in 0.062s)
6. logcat
If you want to control the format of each log entry is dumped, you need to use the "adb logcat -v <format>" option, which supports the following formats:
"adb logcat -v brief" - Display priority/tag and the PID of process issuing the message (the default format).
"adb logcat -v process" - Display PID only.
"adb logcat -v tag" - Display the priority/tag only.
"adb logcat -v raw" - Display the raw log message, with no other metadata fields.
"adb logcat -v time" - Display the date, invocation time, priority/tag, and PID of the process issuing the message.
"adb logcat -v thread" - Display the priority, tag, and the PID and TID of the thread issuing the message.
"adb logcat -v threadtime" - Display the date, invocation time, priority, tag, and the PID and TID of the thread issuing the message.
"adb logcat -v long" - Display all metadata fields and separate messages with a blank lines.
一般使用这个参数
$ adb logcat -v threadtime &
7. 端口转发
$ adb forward tcp:port tcp:port
在使用gdb或ARM DS-5, host和target需要进行通讯时,要设置这个,否则无法正常通信。
adb 常见问题
1. adb devices no permissions
$ adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
???????????? no permissions
$ adb shell
error: insufficient permissions for device
解决方法:
$ sudo adb kill-server
$ sudo adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
19761202 device
2. adb push时失败, Read-only file system
$ adb -d push ../../out/target/product/generic/system/bin/myloop /system/bin
failed to copy '../../out/target/product/generic/system/bin/myloop' to '/system/bin/myloop': Read-only file system
解决方法1:
$ adb root
$ adb remount
remount succeeded
$ adb -d push ../../out/target/product/generic/system/bin/myloop /system/bin
101 KB/s (5504 bytes in 0.052s)
解决方法2:
$ adb shell
# su
# mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
# chmod 777 /system
# exit