注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

liangxh2008的博客

 
 
 

日志

 
 

adb (Android Debug Bridge) Android 调试桥  

2010-03-24 18:47:59|  分类: pc sync |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

 

Android Debug Bridge (adb) 是一个通用的工具让你管理Android模拟器实例. 这个程序是C/S类型,包括三个组件:

客户端: 在开发者机器上运行,通过命令行调用.然 ADT 插件和 DDMS 也可以创建adb 客户进程.
服务器: 在开发者机器后台运行的adb进程. 服务器负责管理客户与adb守护进程的通信.守护进程运行在模拟器/设备上.
守护进程: 作为一个后台进程运行在模拟器/设备上.

当你启动一个adb客户进程,客户进程首先检查是否有一个服务进程已经运行.如果没有,则启动一个服务进程.
当服务进程启动时,它绑定本志TCP 5037 端口并监听所有客户端发出的命令.所有adb 客户通过 5037 商品与服务器通信.
服务器通过扫描 模拟器/设备 5555-5585 的奇数端口,与所有模拟器/设备的实例建立连接.当服务器发现一个adb 守护进程,将会在模拟器/设备的端口上建立连接.
注意模拟器的端口必须是一对连接的端口.偶数端口连接控制台,奇数端口用于adb连接.
示例:
Emulator 1, console: 5554
Emulator 1, adb: 5555

Emulator 2, console: 5556
Emulator 2, adb: 5557

...

一旦服务器与所有模拟器实例建立连接,你便可以使用adb 命令控制访问那些实例.由于服务器管理所有的模拟器实例并处理多个adb 客户端的命令,因此你可以在任何一个客户端控制任何一个模拟器实例.

如果使用IDE,并且安装了ADT插件.你可以不用在命令行访问adb.
当然,为了调试你也可以在命令行下使用adb工具.

命令行下 adb 的使用:

引用

D:\WINDOWS\system32>adb
Android Debug Bridge version 1.0.20

-d                            - directs command to the only connected USB devic
e
                                 returns an error if more than one USB device is
present.
-e                            - directs command to the only running emulator.
                                 returns an error if more than one emulator is r
unning.
-s <serial number>            - directs command to the USB device or emulator w
ith
                                 the given serial number
-p <product name or path>     - simple product name like 'sooner', or
                                 a relative/absolute path to a product
                                 out directory like 'out/target/product/sooner'.

                                 If -p is not specified, the ANDROID_PRODUCT_OUT

                                 environment variable is used, which must
                                 be an absolute path.
devices                       - list all connected devices

device commands:
  adb update DATAOPTS <file>   - Flash the specified update file.
                                 If file is not passed, update.zip is used.
  adb push <local> <remote>    - copy file/dir to device
  adb pull <remote> <local>    - copy file/dir from device
  adb sync [ <localdir> ]      - copy host->device only if changed
                                 (see 'adb help all')
  adb shell                    - run remote shell interactively
  adb shell <command>          - run remote shell command
  adb emu <command>            - run emulator console command
  adb logcat [ <filter-spec> ] - View device log
  adb forward <local> <remote> - forward socket connections
                                 forward specs are one of:
                                   tcp:<port>
                                   localabstract:<unix domain socket name>
                                   localreserved:<unix domain socket name>
                                   localfilesystem:<unix domain socket name>
                                   dev:<character device name>
                                   jdwp:<process pid> (remote only)
  adb jdwp                     - list PIDs of processes hosting a JDWP transport

  adb install [-l] [-r] <file> - push this package file to the device and instal
l it
                                 ('-l' means forward-lock the app)
                                 ('-r' means reinstall the app, keeping its data
)
  adb uninstall [-k] <package> - remove this app package from the device
                                 ('-k' means keep the data and cache directories
)
  adb bugreport                - return all information from the device
                                 that should be included in a bug report.

  adb help                     - show this help message
  adb version                  - show version num

DATAOPTS:
(no option)                   - don't touch the data partition
  -w                           - wipe the data partition
  -d                           - flash the data partition

bootloader commands:
  adb flashall DATAOPTS        - reflash the device from the build output tree
  adb flash [<name>] [<file>]  - write to flash
  adb send <name> <file>       - write to ram
  adb debug                    - listen to bootloader debuglog
  adb bl <command>             - send raw bootloader command

scripting:
  adb wait-for-bootloader      - block until bootloader is online
  adb wait-for-device          - block until device is online
  adb start-server             - ensure that there is a server running
  adb kill-server              - kill the server if it is running
  adb get-state                - prints: offline | bootloader | device
  adb get-product              - prints: <product-id>
  adb get-serialno             - prints: <serial-number>
  adb status-window            - continuously print device status for a specifie
d device
  adb remount                  - remounts the /system partition on the device re
ad-write

networking:
  adb ppp <tty> [parameters]   - Run PPP over USB.
Note: you should not automatically start a PDP connection.
<tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1
[parameters] - Eg. defaultroute debug dump local notty usepeerdns

adb sync notes: adb sync [ <localdir> ]
  <localdir> can be interpreted in several ways:

  - If it not specified, both /system and /data partitions will be updated.

  - If it is "system" or "data", only the corresponding partition
    is updated.

  - If it is a path to a local directory, the name is examined to see if
    it points to a directory named ".../system" or ".../data", or if
    the directory contains subdirectories with those names.  If so, it pushes
    the appropriate directory/ies to the device.

  - If the name of the local directory does not match ".../system" or
    ".../data", it is treated like an "system" directory.

  - If <localdir> points to a nonexistent directory, adb sync will fail.



引用

adb [-d|-e|-s <serialNumber>] <command>


查询模拟器/设备:
引用
adb devices


若没有:
引用


D:\WINDOWS\system32>adb devices
List of devices attached



启动一个模拟器
引用


D:\WINDOWS\system32>emulator
emulator: emulator window was out of view and was recentred



若有:
引用


D:\WINDOWS\system32>adb devices
List of devices attached
emulator-5554   device



Serial number :惟一的模拟器/设备的标识符.
格式:
<type>-<consolePort>
比如: emulator-5554

State:连接状态
offline :没有adb连接
device :有 adb连接


直接连接指定模拟器/设备,根据设备 Serial number.
引用

adb -s <serialNumber> <command>


直接连接指定模拟器/设备,根据设备 Serial number.并执行命令.
引用

adb -s emulator-5556 install helloWorld.apk


安装应用程序
引用

adb install <path_to_apk>


端口转发
引用

adb forward tcp:6100 tcp:7100

可以使用 抽象 UNIX 域套接字:
引用

adb forward tcp:6100 local:logd


文件操作
拷出:
引用

adb pull <remote> <local>

拷入:
引用

adb push <local> <remote>


比如:

引用

adb push foo.txt /sdcard/foo.txt


adb 命令列表:

引用

Options -d Direct an adb command to the only attached USB device. Returns an error if more than one USB device is attached.
-e Direct an adb command to the only running emulator instance. Returns an error if more than one emulator instance is running. 
-s <serialNumber> Direct an adb command a specific emulator/device instance, referred to by its adb-assigned serial number (such as "emulator-5556"). If not specified, adb generates an error.
General devices Prints a list of all attached emulator/device instances. See Querying for Emulator/Device Instances for more information.
help Prints a list of supported adb commands.  
version Prints the adb version number.   
Debug logcat [<option>] [<filter-specs>] Prints log data to the screen.   
bugreport Prints dumpsys, dumpstate, and logcat data to the screen, for the purposes of bug reporting.   
jdwp Prints a list of available JDWP processes on a given device.  You can use the forward jdwp:<pid> port-forwarding specification to connect to a specific JDWP process. For example:
adb forward tcp:8000 jdwp:472
jdb -attach localhost:8000

Data install <path-to-apk> Pushes an Android application (specified as a full path to an .apk file) to the data file of an emulator/device.   
pull <remote> <local> Copies a specified file from an emulator/device instance to your development computer.   
push <local> <remote> Copies a specified file from your development computer to an emulator/device instance.   
Ports and Networking forward <local> <remote> Forwards socket connections from a specified local port to a specified remote port on the emulator/device instance.  Port specifications can use these schemes:
tcp:<portnum>
local:<UNIX domain socket name>
dev:<character device name>
jdwp:<pid>

ppp <tty> [parm]... Run PPP over USB.
<tty> — the tty for PPP stream. For example dev:/dev/omap_csmi_ttyl.
[parm]... &mdash zero or more PPP/PPPD options, such as defaultroute, local, notty, etc.
Note that you should not automatically start a PDP connection.
 
Scripting get-serialno Prints the adb instance serial number string. See Querying for Emulator/Device Instances for more information. 
get-state Prints the adb state of an emulator/device instance.
wait-for-device Blocks execution until the device is online — that is, until the instance state is device. You can prepend this command to other adb commands, in which case adb will wait until the emulator/device instance is connected before issuing the other commands. Here's an example: adb wait-for-device shell getpropNote that this command does not cause adb to wait until the entire system is fully booted. For that reason, you should not prepend it to other commands that require a fully booted system. As an example, the install requires the Android package manager, which is available only after the system is fully booted. A command such as adb wait-for-device install <app>.apkwould issue the install command as soon as the emulator or device instance connected to the adb server, but before the Android system was fully booted, so it would result in an error. 
Server start-server Checks whether the adb server process is running and starts it, if not.  
kill-server Terminates the adb server process.  
Shell shell Starts a remote shell in the target emulator/device instance. See Issuing Shell Commands for more information. 
shell [<shellCommand>] Issues a shell command in the target emulator/device instance and then exits the remote shell.





调用Shell命令

启动shell:
引用

adb [-d|-e|-s {<serialNumber>}] shell


获取命令列表:
ls /system/bin/

通过shell操作SQLite3数据库

模拟器/设备的数据库存储在 /data/data/<package_name>/databases/.

示例:

引用

$ adb -s emulator-5554 shell
# sqlite3 /data/data/com.example.google.rss.rssexample/databases/rssitems.db
SQLite version 3.3.12
Enter ".help" for instructions
.... enter commands, then quit...
sqlite> .exit


Monkey介绍:
Monkey 用于生成随机事件测试程序,可以模仿用户操作,而不用手动.一般在压力测试中用到.

示例:
生成500个随机事件.
引用

$ adb shell monkey -v -p your.package.name 500




logcat 日志操作

引用

[adb] logcat [<option>] ... [<filter-spec>] ...


过滤日志输出:
级别:
V — 详细 (最低优先级)
D — 调试
I — 信息
W — 警告
E — 错误
F — 严重错误
S — 静默(无输出)

TAG:用于过滤同级别日志输出.作为过滤条件.

控制显示格式:

brief — Display priority/tag and PID of originating process (the default format).
process — Display PID only.
tag — Display the priority/tag only.
thread — Display process:thread and priority/tag only.
raw — Display the raw log message, with no other metadata fields.
time — Display the date, invocation time, priority/tag, and PID of the originating process.
long — Display all metadata fields and separate messages with a blank lines.

引用

[adb] logcat [-v <format>]


引用
adb logcat -v thread

注意:只能指定一种.

启动,停止adb server
引用

adb start-server
adb kill-server


  评论这张
 
阅读(772)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018