User Tools

Site Tools


how_to_debug_android_by_adb

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

how_to_debug_android_by_adb [2013/12/23 14:50] (current)
Line 1: Line 1:
 +====== How To Debug Android By Adb ======
 +
 +
 +<WRAP noprint><​WRAP left box 60%>
 +//__About this Article__//
 +  * **Author**: parker --- parker@cubietech.com --- 2013/11/1 09:30
 +  * **Copyrights**:​ [[http://​creativecommons.org/​licenses/​by-sa/​3.0/​|CC Attribution-Share Alike 3.0 Unported]]
 +  * **Contributors**:​ [[http://​cubieboard.org/​|Cubieboard Community]] : ...
 +</​WRAP></​WRAP>​
 +
 +===== What is the ADB =====
 +Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device. It is a client-server program that includes three components: ​
 +
 +  * 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. ​
 +<code bash>
 +You can find the adb tool in <​sdk>/​platform-tools/​.
 +</​code>​
 +\\
 +The server then sets up connections to all running emulator/​device instances. It locates emulator/​device instances by scanning odd-numbered ports in the range 5555 to 5585, the range used by emulators/​devices. ​
 +Where the server finds an adb daemon, it sets up a connection to that port. Note that each emulator/​device instance acquires a pair of sequential ports — an even-numbered port for console connections and an odd-numbered port for adb connections. ​
 +
 +===== How to use ADB =====
 +  * Similar to many commands,​when you don't know what can the usb do,you can import:
 +<code bash>
 + $adb help
 +</​code>​
 +
 +  * Then you will see some introductions
 +<code bash>
 +device commands:
 +  adb push <​local>​ <​remote> ​   - copy file/dir to device
 +  adb pull <​remote>​ [<​local>​] ​ - copy file/dir from device
 +  adb sync [ <​directory>​ ]     - 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 <​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)
 +
 +</​code>​\\
 +
 +
 +
 +=== Directing Commands to a Specific Emulator/​Device Instance ===
 +
 +  * You can specify the target instance for a command using its adb-assigned serial number. You can use the devices command to obtain the serial numbers of running emulator/​device instances. For example: ​
 +<code bash>
 + $adb -s emulator-5556 install helloWorld.apk
 +</​code>​\\
 +
 +**Note**:if you issue a command without specifying a target emulator/​device instance while multiple devices are available, adb generates an error. \\
 +
 +===Installing and unstalling 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:
 +<code bash>
 + $adb install <​path_to_apk>​
 +</​code>​
 +And then uninstall it:
 +<code bash>
 + $adb uninstall <​path_to_apk>​
 +</​code>​
 +
 +  * if you are using the Eclipse IDE and have the ADT plugin installed, you do not need to use adb (or aapt) directly to install your application on the emulator/​device. Instead, the ADT plugin handles the packaging and installation of the application for you. 
 +
 +===Copying Files to or from an Emulator/​Device Instance===
 +
 +You can use the adb commands pull and push to copy files to and from an emulator/​device instance. Unlike the install command, which only copies an APK file to a specific location, the pull and push commands let you copy arbitrary directories and files to any location in an emulator/​device instance. ​
 +
 +  * You can use this to copy file or directory from the emulator or device:
 +<code bash>
 + $adb pull <​remote>​ <​local>​
 +</​code>​
 +  * You can use this to copy file or directory to the emulator or device:
 +<code bash>
 + $adb push <​remote>​ <​local>​
 +</​code>​\\
 +**Note**:In the commands, ''<​local>''​ and ''<​remote>''​ refer to the paths to the target files/​directory on your development machine (local) and on the emulator/​device instance (remote). For example: ​
 +<code bash>
 + $adb push /​work/​tools/​adb.txt /system
 +</​code>​
 +
 +===Issuing Shell Commands===
 +  * You can use the shell command to issue commands, with or without entering the adb remote shell on the emulator/​device.To issue a single command without entering a remote shell, use the shell command like this: 
 +<code bash>
 + $adb [-d|-e|-s <​serialNumber>​] shell <​shell_command>​
 +</​code>​
 +  * Or enter a remote shell on an emulator/​device like this:
 +<code bash>
 + $adb [-d|-e|-s <​serialNumber>​] shell
 +</​code>​
 +  * When you are ready to exit the remote shell, press CTRL+D or type exit. 
 +{{:​adb6.png}}
 +
 +===Enabling logcat logging===
 +\\
 +The Android logging system provides a mechanism for collecting and viewing system debug output. Logs from various applications and portions of the system are collected in a series of circular buffers, which then can be viewed and filtered by the logcat command.
 +  * You can use the logcat command to view and follow the contents of the system'​s log buffers. The general usage is:
 +<code bash>
 +[adb] logcat [option] ... [filter-spec] ...
 +</​code>​
 +  * You can use the logcat command from your development computer or from a remote adb shell in an emulator/​device instance. To view log output in your development computer, you use
 +<code bash>
 + $adb logcat
 +</​code>​
 +  * and from a remote adb shell you use
 +<code bash>
 + ​$logcat
 +</​code>​
 +
 +===== Unable to connect adb =====
 +Some people will get such note when they use ''​$adb device''​
 +<code bash>
 +List of devices attached
 +????????????​ no permissions
 +</​code>​
 +
 +  * It is say that you don't have the permission to run ADB by USB.So you can set the USB permission.
 +  * (1)find your USB ID:
 +<code bash>
 +$ lsusb
 +Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 +Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 +Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 +Bus 001 Device 003: ID 18d1:0003 Google Inc.
 +Bus 002 Device 002: ID 0461:4d81 Primax Electronics,​ Ltd
 +Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 +Bus 001 Device 010: ID 0bb4:0c87 High Tech Computer Corp.
 +Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 +</​code>​
 +**Note**: And then find your USB ID.Here I can find my USB ID is ''​Bus 001 Device 003: ID 18d1:0003 Google Inc.''​
 +
 +  * (2)Add the rule
 +<code bash>
 + $sudo vim /​etc/​udev/​rules.d/​70-android.rules
 +</​code>​
 +
 +  * (3)Add the message
 +<code bash>
 + ​SUBSYSTEM=="​usb",​ ATTRS{idVendor}=="​18d1",​ ATTRS{idProduct}=="​0003",​MODE="​0666"​
 +</​code>​
 +**Note**:​The ​ ''​18d1'' ​ and  ''​0003'' ​ is my ID,you must add your ID.
 +
 +  * (4)Restart the service
 +<code bash>
 + $sudo chmod a+rx /​etc/​udev/​rules.d/​70-android.rules
 + $sudo service udev restart
 +</​code>​
 +
 +  *  (5)Swap the USB cable and enter the directory where have the adb.
 +<code bash>
 + $sudo ./adb kill-server
 + ​$./​adb devices
 + ​$./​adb root
 +</​code>​
 +
 +
 +
 +
  
how_to_debug_android_by_adb.txt · Last modified: 2013/12/23 14:50 (external edit)