`

adb (Android Debug Bridge) Android 调试桥

阅读更多
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

























分享到:
评论

相关推荐

    Android Debug Bridge(安卓调试桥)

    adb工具即Android Debug Bridge(安卓调试桥) tools。它就是一个命令行窗口,用于通过电脑端与模拟器或者真实设备交互。在某些特殊的情况下进入不了系统,adb就派上用场啦! adb工具我觉得很重要,比如说你的手机不...

    Android Debug Bridge(安卓调试桥) tools

    adb工具即Android Debug Bridge(安卓调试桥) tools。它就是一个命令行窗口,用于通过电脑端与模拟器或者真实设备交互。在某些特殊的情况下进入不了系统,adb就派上用场啦! adb工具我觉得很重要,比如说你的手机不...

    adb工具即Android Debug Bridge(安卓调试桥) tools

    adb工具即Android Debug Bridge(安卓调试桥) tools..

    ADB.zip ADB(Android Debug Bridge)安卓调试桥

    ADB(Android Debug Bridge)安卓调试桥

    安卓调试桥adb

    adb1.0.32 Android Debug Bridge(ADB)ADB的全称为Android Debug Bridge,就是调试桥的作用,存放在sdk安装目录下的platform-tools文件夹中,借助这个工具,我们可以管理设备或手机模拟器的状态,可以让你与仿真实例...

    Android Debug Bridge version 1.0.32

    adb的全称为Android Debug Bridge 调试桥,是连接Android手机与PC端的桥梁,通过adb可以管理、操作模拟器和设备,如安装软件、查看设备软硬件参数、系统升级、运行shell命令等。

    Android Debug Bridge (adb).zip

    adb的全称为Android Debug Bridge,就是起到调试桥的作用。通过adb我们可以在Eclipse中方便通过DDMS来调试Android程序,说白了就是debug工具。

    关于ADB的Android Debug Bridge(安卓调试桥)那些事

    主要介绍了关于ADB的Android Debug Bridge(安卓调试桥)那些事,需要的朋友可以参考下

    Android 调试桥adb

    Android 调试桥 adb Android 调试桥 adb Android 调试桥 adb

    adb(Android Debug Bridge)

    安卓系统Android Debug Bridge(ADB)免安装绿色版。

    adb程序(Android Debug Bridge)

    adb的全称为Android Debug Bridge,就是起到调试桥的作用,是客户端测试常用的辅助工具。借助adb工具,我们可以管理设备或手机模拟器的状态。还可以进行很多终端操作,如安装软件、卸载软件、系统升级、运行shell...

    Android Debug Bridge(安卓调试桥) tools platform-tools adb命令行工具

    启动 adb server 命令:adb start-server 停止 adb server 命令:adb kill-server 查询已连接设备/模拟器:adb devices 该命令经常出现以下问题: offline —— 表示设备未连接成功或无响应; device —— 设备已...

    adb是Android Debug Bridge的缩写

    adb是Android Debug Bridge的缩写,是一个用于在计算机和Android设备之间进行通信的命令行工具。它可以用于安装和调试应用程序,以及在设备和计算机之间传输文件等。

    Android Debug Bridge 下载 download

    Android Debug Bridge (adb) 是一个android开发人员必会的多功能的调试工具,确实它的名字一样,它在开发者和目标机器之间,架起了一座bridge。 adb的用法很简单,只要看完SDK文档关于ADB的部分,(android-sdk-...

    adb的全称为Android Debug Bridge

    adb的全称为Android Debug Bridge,就是起到调试桥的作用。通过adb我们可以在Eclipse中方面通过DDMS来调试Android程序,说白了就是debug工具。

    Android Debug Bridge(ADB)命令行工具

    应用程序调试:开发人员可以使用ADB在Android设备上运行和调试应用程序,查看应用程序的日志和调试信息,以便更容易地排除错误和问题。 Shell访问:ADB允许开发人员通过命令行访问设备的Shell,可以在设备上执行...

    Google提供的adb工具(Android Debug Bridge)

    Google提供的Android调试工具,将设备通过usb与电脑连接,实现相关调试功能。在电脑中调出该工具,在其中输入类似: adb install *.apk 安装软件,同样的,类似:adb shell df 可以查看设备的存储信息等等! 常用的...

Global site tag (gtag.js) - Google Analytics