http://www.csdn123.com/html/itweb/20131015/168574.htm

ADB命令简介

  ADB是一个功能强大的命令行工具。通过它可以直接和模拟器或真机进行交互。它是一个具有客户端和服务器端的程序。

  它主要由三个部分组成

  1. 客户端,它运行在你的开发机上,你可以通过执行adb命令来唤起一个客户端。其他的工具例如:ADT插件以及DDMS也可以创建一个ADB客户端。
  2. 服务端,它运行在你的后台进程,这个服务管理客户端和运行在你模拟起或真机上的守护进程。
  3. 守护进程,它运行在每台模拟器或真机的后台进程。

  当你启动一个adb客户端的时候,客户端会首先检测是否已经有adb服务进程运行,如果没有运行,那么它会首先启动一个服务进程,当服务进程启动后,服务进程绑定本地的5037端口,并且监听所有来自adb 客户端的命令,所有的adb客户端通过5037与adb 服务端进行交互。

  服务端运行之后与所有运行的模拟器或真机建立链接,它通过一组范围从5555 到5585的奇数的端口检索到所有的模拟器或真机。每一台模拟器或真机需要获取一对连续的端口,偶数端口用于控制台的链接,奇数端口用于adb的链接。

  当然,如果你用Eclipse开发,并且也安装了ADT插件,那么你没必要通过adb命令行与模拟器或真机交互,ADT插件已经完美的将adb整合进了Eclipse IDE.当然还是提倡多使用adb命令行,这样的话比较方便自定义debug方法,同时也可以更好的理解其工作原理。

Adb命令列表

  下列表格列出了adb支持的命令,并对它们的意义和使用方法做了说明.

Category Command Description Comments
Options -d 仅仅通过USB接口来管理abd. 如果不只是用USB接口来管理则返回错误.
-e 仅仅通过模拟器实例来管理adb. 如果不是仅仅通过模拟器实例管理则返回错误.
-s <serialNumber> 通过模拟器/设备的允许的命令号码来发送命令来管理adb (比如: "emulator-5556"). 如果没有指定号码,则会报错.
General devices 查看所有连接模拟器/设备的设施的清单. 查看 Querying for Emulator/Device Instances获取更多相关信息.
help 查看adb所支持的所有命令。.  
version 查看adb的版本序列号.  
Debug logcat [<option>] [<filter-specs>] 将日志数据输出到屏幕上.  
bugreport 查看bug的报告,如dumpsys ,dumpstate ,和logcat 信息。  
jdwp 查看指定的设施的可用的JDWP信息. 可以用 forward jdwp:<pid> 端口映射信息来连接指定的JDWP进程.例如: 
adb forward tcp:8000 jdwp:472 
jdb -attach localhost:8000
Data install <path-to-apk> 安装Android为(可以模拟器/设施的数据文件.apk指定完整的路径).  
pull <remote> <local> 将指定的文件从模拟器/设施的拷贝到电脑上.  
push <local> <remote> 将指定的文件从电脑上拷贝到模拟器/设备中.  
Ports and Networking forward <local> <remote> 用本地指定的端口通过socket方法远程连接模拟器/设施 端口需要描述下列信息:
  • tcp:<portnum>
  • local:<UNIX domain socket name>
  • dev:<character device name>
  • jdwp:<pid>
ppp <tty> [parm]... 通过USB运行ppp:
  • <tty> — the tty for PPP stream. For exampledev:/dev/omap_csmi_ttyl.
  • [parm]...  &mdash zero or more PPP/PPPD options, such as defaultroute ,local , notty , etc.

需要提醒你的不能自动启动PDP连接.

 
Scripting get-serialno 查看adb实例的序列号. 查看 Querying for Emulator/Device Instances可以获得更多信息.
get-state 查看模拟器/设施的当前状态.
wait-for-device 如果设备不联机就不让执行,--也就是实例状态是 device 时. 你可以提前把命令转载在adb的命令器中,在命令器中的命令在模拟器/设备连接之前是不会执行其它命令的. 示例如下:
adb wait-for-device shell getprop
需要提醒的是这些命令在所有的系统启动启动起来之前是不会启动adb的 所以在所有的系统启动起来之前你也不能执行其它的命令. 比如:运用install 的时候就需要Android包,这些包只有系统完全启动。例如:
adb wait-for-device install <app>.apk
上面的命令只有连接上了模拟器/设备连接上了adb服务才会被执行,而在Android系统完全启动前执行就会有错误发生.
Server start-server 选择服务是否启动adb服务进程.  
kill-server 终止adb服务进程.  
Shell shell 通过远程shell命令来控制模拟器/设备实例. 查看 获取更多信息 for more information.
shell [<shellCommand>] 连接模拟器/设施执行shell命令,执行完毕后退出远程shell端l.

  adb命令参数详解

# adb --help
Android Debug Bridge version 1.0.29

 -d                            - directs command to the only connected USB device
                                 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 running.
 -s             - directs command to the USB device or emulator with
                                 the given serial number. Overrides ANDROID_SERIAL
                                 environment variable.
 -p      - 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
 connect [:]       - connect to a device via TCP/IP
                                 Port 5555 is used by default if no port number is specified.
 disconnect [[:]]  - disconnect from a TCP/IP device.
                                 Port 5555 is used by default if no port number is specified.
                                 Using this command with no additional arguments
                                 will disconnect from all connected TCP/IP devices.

device commands:
  adb push      - copy file/dir to device
  adb pull  []  - copy file/dir from device
  adb sync [  ]     - copy host->device only if changed
                                 (-l means list but don't copy)
                                 (see 'adb help all')
  adb shell                    - run remote shell interactively
  adb shell           - run remote shell command
  adb emu             - run emulator console command
  adb logcat [  ] - View device log
  adb forward   - forward socket connections
                                 forward specs are one of:
                                   tcp:
                                   localabstract:
                                   localreserved:
                                   localfilesystem:
                                   dev:
                                   jdwp: (remote only)
  adb jdwp                     - list PIDs of processes hosting a JDWP transport
  adb install [-l] [-r] [-s] [--algo  --key  --iv ]
                               - push this package file to the device and install it
                                 ('-l' means forward-lock the app)
                                 ('-r' means reinstall the app, keeping its data)
                                 ('-s' means install on SD card instead of internal storage)
                                 ('--algo', '--key', and '--iv' mean the file is encrypted already)
  adb uninstall [-k]  - 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 backup [-f ] [-apk|-noapk] [-shared|-noshared] [-all] [-system|-nosystem] []
                               - write an archive of the device's data to .
                                 If no -f option is supplied then the data is written
                                 to "backup.ab" in the current directory.
                                 (-apk|-noapk enable/disable backup of the .apks themselves
                                    in the archive; the default is noapk.)
                                 (-shared|-noshared enable/disable backup of the device's
                                    shared storage / SD card contents; the default is noshared.)
                                 (-all means to back up all installed applications)
                                 (-system|-nosystem toggles whether -all automatically includes
                                    system applications; the default is to include system apps)
                                 ( is the list of applications to be backed up.  If
                                    the -all or -shared flags are passed, then the package
                                    list is optional.  Applications explicitly given on the
                                    command line will be included even if -nosystem would
                                    ordinarily cause them to be omitted.)

  adb restore            - restore device contents from the  backup archive

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

scripting:
  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-serialno             - prints:
  adb status-window            - continuously print device status for a specified device
  adb remount                  - remounts the /system partition on the device read-write
  adb reboot [bootloader|recovery] - reboots the device, optionally into the bootloader or recovery program
  adb reboot-bootloader        - reboots the device into the bootloader
  adb root                     - restarts the adbd daemon with root permissions
  adb usb                      - restarts the adbd daemon listening on USB
  adb tcpip              - restarts the adbd daemon listening on TCP on the specified port
networking:
  adb ppp  [parameters]   - Run PPP over USB.
 Note: you should not automatically start a PPP connection.
  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 [  ]
   can be interpreted in several ways:

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

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

environmental variables:
  ADB_TRACE                    - Print debug information. A comma separated list of the following values
                                 1 or all, adb, sockets, packets, rwx, usb, sync, sysdeps, transport, jdwp
  ANDROID_SERIAL               - The serial number to connect to. -s takes priority over this if given.
  ANDROID_LOG_TAGS             - When used with the logcat option, only these debug tags are printed.
View Code

  查看所有当前通过USB设备连接的设备

# adb devices
List of devices attached
emulator-5554    device
0288424641407417    device
HT9CRP810308    device
View Code

相关文章: