清澄 世界

關於部落格
三朵花的爸 第四朵花的他
  • 12380

    累積人氣

  • 0

    今日人氣

    0

    訂閱人氣

Introduction of Android Debug Bridge (ADB)

Android Debug Bridge(ADB) adb工具用於向模擬器或設備安裝應用程序的.apk文件和從命令行訪問模擬器或設備。 也可以用於將標準的調試器連接到運行在Android模擬器或設備上的應用程序代碼上。 他是通用的debug工具使你管理設備或者模擬器的狀態
ADB在運行上是一種Client-Server的模式,主要包含三個部分:
  • A client:  which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients.
  • A server: which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device.
  • A daemon: which runs as a background process on each emulator or device instance
當要開始一個adb client (例如一個adb command 或是 DDMS tool),  client會先去確認是否有adb server程序已經在執行,  若沒有則生成一個adb server process, 當adb server process開始跑起來之後, 他使用TCP port 5037 並且開始監聽從adb client所發出的訊息以及命令—其中所有的adb clients都用port 5037 與adb server溝通.

server 接著開始設定與所有emulator/devices端instances之連結(也就是Server與Instance之間建立關係, client再透過Server進而操作Emulator/Device之Instance). Server找出Instances的方法是去掃瞄所有port範圍在5555到5585之間的單數號, 因為instances與Server溝通所使用的port就是介於這個區域.

值得注意的是每個instance一次要求一組成對的pors:
單數號 port for console connections.
雙數號 port for adb connections.
For Example

Emulator 1, console: 5554
Emulator 1, adb: 5555
Emulator 2, console: 5556
Emulator 2, adb: 5557 ...

As shown, the emulator instance connected to adb on port 5555 is the same as the instance whose console listens on port 5554.

Once the server has set up connections to all emulator instances, you can use adb commands to control and access those instances. Because the server manages connections to emulator/device instances and handles commands from multiple adb clients, you can control any emulator/device instance from any client

Issuing adb Commands

The usage is:
adb [-d|-e|-s <serialNumber>] <command>


ADB提供了一些 command line 指令,來與模擬器或設備端做溝通,相關指令如下:

adb devices
- generate a list of attached emulators/devices
adb -s <serialNumber> <command> 
-Directing Commands to a Specific Emulator/Device Instance, e.g.:  
adb -s emulator-5556 install helloWorld.apk



Installing an Application
You can use adb to copy an application from your development computer and install it on an emulator/device instance. To do so, use the install command. With the command, you must specify the path to the .apk file that you want to install:

adb install <path_to_apk>

Copying files to or from an Emulator/device instance
To copy a file or directory (recursively) from the emulator or device, use
adb pull <remote> <local>
To copy a file or directory (recursively) to the emulator or device, use
adb push <local> <remote>
Here's an example:
adb push 123.txt /root/123.txt

其他詳細用法請參考:
http://android.toolib.info/cndocs/reference/adb.html - Android Official Documents
http://stenlyho.blogspot.com/2008/11/androidadb.html - 史丹利部落格
http://blog.ben.idv.tw/2007/12/android-debug-bridge.html - 邦邦的部落格

相簿設定
標籤設定
相簿狀態