Android adb 命令圖解

fmms 12年前發布 | 51K 次閱讀 Android Android開發 移動開發

做了這么長時間的開發與管理,在命令上總是自見則過,往往卻忽視了在其命令上的分享過程,所以現在稍微有點時間就把 其命令的相關操作來簡單的掃盲一番吧,也系統通過這種方式去授之以漁而不是魚,好了,我以圖解的方式來展示,當然我的習慣就是任何東西先看幫助文檔或者命令,就今天我們這里要講解的ADB命令在命令行中可以通過命令幫助來進行詳細了解,廢話不多說,先上圖吧:

Android adb 命令圖解

Android adb 命令圖解

Android adb 命令圖解

Android adb 命令圖解

以上為使用help來顯示其相關的命令使用說明,當然那個如果你的英文足夠好的話,其實這些都很簡單,當然,如你不太習慣去看這些英文描述的話,那接下來就由我來幫助處理這樣的問題吧,好了,我就以最初始的理解方式來進行翻譯與講解吧,OK:

Android Debug Bridge version 1.0.29
這是關于Android調試牌的1.0.29版本

 -d                            - directs command to the only connected USB device

通過這個直接的命令僅僅是去連接USB設備
                                 returns an error if more than one USB device is present.

如果有多個USB設備同時出現的時候就會返回一個錯誤信息
 -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.

通過這個直接的命令去展示其USB設備或者模擬器的序列號,彼此覆蓋時會使其環境變量是可變的
 -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.

通過此命令顯示其產品的名稱,如"sooner",或者是相對與絕對的產品輸出路徑像"out/target/product/sooner",如果 -p沒有指定的話,就會使用ANDROID_PRODUCT_OUT的環境變量,但必須是一個絕對路徑.
 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.

通過TCP/IP的默認端口5555來連接設備
 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.

使用此命令可以去斷開來自TCP/IP的設備連接,其在沒有指定端口號時默認指定為5555,使用這個命令不需要去增加參數將會斷開來自TCP/IP的所有連接設備

device commands:

設備命令:
  adb push    - copy file/dir to device
PUSH命令:即復制一個文件或者目錄進設備中

  adb pull []  - copy file/dir from device

PULL命令:即復制一個文件或者目錄進設備中
  adb sync [ ]     - copy host->device only if changed
                                 (-l means list but don't copy)
                                 (see 'adb help all')

SYNC:復制主機內容進設備,僅僅是設備進行改變時對其內容進行同步處理的操作,括號里有說明:我的意思是列出但是不需要復制,可參考幫助ALL
  adb shell                    - run remote shell interactively

SHELL:運行遠程SHELL與之交互
  adb shell          - run remote shell command

SHELL:直接運行遠程SHELL命令
  adb emu            - run emulator console command

EMU:運行模擬器監控信息面板命令
  adb logcat [ ] - View device log

閱覽設備日志
  adb forward - forward socket connections

遠期套接字連接
                                 forward specs are one of:

遠期規格顯示的一個標準是:
                                   tcp:

TCP端口號
                                   localabstract:
本地抽象:UNIX域名的SOCKET名稱

                                   localreserved:

本地服務:UNIX域名/SOCKET名稱
                                   localfilesystem:

本地文件系統:UNIX域名/SOCKET名稱
                                   dev:

設備:字符設備名稱
                                   jdwp: (remote only)

遠程進程ID
  adb jdwp                     - list PIDs of processes hosting a JDWP transport

列出相關的進程ID為主機進程的一個JAVA調試的無線協議的傳輸

說道JDWP,我簡單對其說明下,說明是JDWP呢,JDWP的全寫是:Java Debug Wire Protocol:即JAVA調試器無線協議,它定義了調試器(Debugger)和被調試的JAVA虛擬機(target vm)之間的通信協議,在這里,我更要說明下:Debugger與Target vm,Target vm 中運行著我們希望要調試的程序,它與一般運行的 Java 虛擬機沒有什么區別,只是在啟動時加載了 Agent JDWP 從而具備了調試功能。而 debugger 就是我們熟知的調試器,它向運行中的 target vm 發送命令來獲取 target vm 運行時的狀態和控制 Java 程序的執行。Debugger 和 target vm 分別在各自的進程中運行,他們之間的通信協議就是 JDWP。JDWP 與其他許多協議不同,它僅僅定義了數據傳輸的格式,但并沒有指定具體的傳輸方式。這就意味著一個 JDWP 的實現可以不需要做任何修改就正常工作在不同的傳輸方式上(在 JDWP 傳輸接口中會做詳細介紹)。JDWP 是語言無關的。理論上我們可以選用任意語言實現 JDWP。然而我們注意到,在 JDWP 的兩端分別是 target vm 和 debugger。Target vm 端,JDWP 模塊必須以 Agent library 的形式在 Java 虛擬機啟動時加載,并且它必須通過 Java 虛擬機提供的 JVMTI 接口實現各種 debug 的功能,所以必須使用 C/C++ 語言編寫。而 debugger 端就沒有這樣的限制,可以使用任意語言編寫,只要遵守 JDWP 規范即可。JDI(Java Debug Interface)就包含了一個 Java 的 JDWP debugger 端的實現(JDI 將在該系列的下一篇文章中介紹),JDK 中調試工具 jdb 也是使用 JDI 完成其調試功能的。以上介紹的 JDWP agent在調試中扮演的角色為下圖所示:

Android adb 命令圖解

其實我們對其協議簡單分析下,我們可以通過下圖來了解到起握手協議的簡單過程:

Android adb 命令圖解

最后了解下其架構吧:

Android adb 命令圖解

好,從以上我們了解了其JDWP的相關信息,更詳細的信息與操作請在GOOGLE里詳細查詢與了解吧.

  adb install [-l] [-r] [-s] - 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)

通過這個命令來對其打包的APK進行安裝進設備中,-l意味著遠期鎖定期APP,-r意味著需要重新安裝這個APP,當然需要對其數據進行保持,-s意味著安裝進SD卡中
  adb uninstall [-k] - remove this app package from the device
                                 ('-k' means keep the data and cache directories)

通過這個命令來卸載其安裝好的APK,即移除當前的APP來自設備的包,-k意味著保持數據域緩存目錄
  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

重新啟動后獲得ROOT權限
  adb usb                      - restarts the adbd daemon listening on USB

重新啟動來監聽器USB
  adb tcpip             - restarts the adbd daemon listening on TCP on the specified port

重新啟動TCP來監聽指定的TCP端口
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.

以上部分由于時間問題就不翻譯與理解了,其實后面幾句都非常好理解,自己也嘗試著去做一下吧,

下面就進行一個簡單的例子:

顯示日志: adb logcat | more

Android adb 命令圖解

列出設備: adb devices

Android adb 命令圖解

OK,以上是簡單的兩個命令列子,你自己可以根據實際情況去帶入相關參數即可對其命令進行校驗了,好了,希望能給大家做一定的參考與學習.......

轉自:http://blog.csdn.net/jiangshide/article/details/7487928

 本文由用戶 fmms 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!