ANDRIOD DEBUG BRIDGE (ADB) - LINK VEB
SUBTOTAL :

Header Ads

App Technology
ANDRIOD DEBUG BRIDGE (ADB)

ANDRIOD DEBUG BRIDGE (ADB)

App Technology
Short Description:

Product Description



Android Debug Bridge (adb) is a versatile command-line tool that lets you communicate with a device (an emulator or a connected Android device). The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device. It is a client-server program that includes three components:
  • A client, which sends commands. The client runs on your development machine. You can invoke a client from a command-line terminal by issuing an adb command.
  • A daemon (adbd), which runs commands on a device. The daemon runs as a background process on each device.
  • A server, which manages communication between the client and the daemon. The server runs as a background process on your development machine.
adb is included in the Android SDK Platform-Tools package. You can download this package with the SDK Manager, which installs it at android_sdk/platform-tools/. Or if you want the standalone Android SDK Platform-Tools package, you can download it here.

How adb works


When you start an adb client, the client first checks whether there is an adb server process already running. If there isn't, it starts the server process. When the server starts, it binds to local TCP port 5037 and listens for commands sent from adb clients—all adb clients use port 5037 to communicate with the adb server.
The server then sets up connections to all running devices. It locates emulators by scanning odd-numbered ports in the range 5555 to 5585, the range used by the first 16 emulators. Where the server finds an adb daemon (adbd), it sets up a connection to that port. Note that each emulator uses a pair of sequential ports — an even-numbered port for console connections and an odd-numbered port for adb connections. For example:
Emulator 1, console: 5554
Emulator 1, adb: 5555
Emulator 2, console: 5556
Emulator 2, adb: 5557
and so on...
As shown, the emulator connected to adb on port 5555 is the same as the emulator whose console listens on port 5554.
Once the server has set up connections to all devices, you can use adb commands to access those devices. Because the server manages connections to devices and handles commands from multiple adb clients, you can control any device from any client (or from a script).

Enable adb debugging on your device


To use adb with a device connected over USB, you must enable USB debugging in the device system settings, under Developer options.
On Android 4.2 and higher, the Developer options screen is hidden by default. To make it visible, go to Settings > About phone and tap Build number seven times. Return to the previous screen to find Developer options at the bottom.
On some devices, the Developer options screen might be located or named differently.
You can now connect your device with USB. You can verify that your device is connected by executing adb devices from the android_sdk/platform-tools/ directory. If connected, you'll see the device name listed as a "device."
Note: When you connect a device running Android 4.2.2 or higher, the system shows a dialog asking whether to accept an RSA key that allows debugging through this computer. This security mechanism protects user devices because it ensures that USB debugging and other adb commands cannot be executed unless you're able to unlock the device and acknowledge the dialog.
For more information about connecting to a device over USB.

Connect to a device over Wi-Fi


adb usually communicates with the device over USB, but you can also use adb over Wi-Fi after some initial setup over USB, as described below. If you're developing for Android Wear, however, you should instead see the guide to debugging an Android Wear app, which has special instructions for using adb with Wi-Fi and Bluetooth.
  1. Connect your Android device and adb host computer to a common Wi-Fi network accessible to both. Beware that not all access points are suitable; you might need to use an access point whose firewall is configured properly to support adb.
  2. If you are connecting to an Android Wear device, turn off Bluetooth on the phone that's paired with the device.
  3. Connect the device to the host computer with a USB cable.
  4. Set the target device to listen for a TCP/IP connection on port 5555.
    adb tcpip 5555
    
  5. Disconnect the USB cable from the target device.
  6. Find the IP address of the Android device. For example, on a Nexus device, you can find the IP address at Settings > About tablet (or About phone) > Status > IP address. Or, on an Android Wear device, you can find the IP address at Settings > Wi-Fi Settings > Advanced > IP address.
  7. Connect to the device by its IP address.
    adb connect device_ip_address
    
  8. Confirm that your host computer is connected to the target device:
    $ adb devices
    List of devices attached
    device_ip_address:5555 device
    
You're now good to go!
If the adb connection is ever lost:
  1. Make sure that your host is still connected to the same Wi-Fi network your Android device is.
  2. Reconnect by executing the adb connect step again.
  3. Or if that doesn't work, reset your adb host:
    adb kill-server
    
    Then start over from the beginning.

Query for devices


Before issuing adb commands, it is helpful to know what device instances are connected to the adb server. You can generate a list of attached devices using the devices command.
  adb devices -l
  
In response, adb prints this status information for each device:
  • Serial number: A string created by adb to uniquely identify the device by its port number. Here's an example serial number: emulator-5554
  • State: The connection state of the device can be one of the following:
    • offline: The device is not connected to adb or is not responding.
    • device: The device is now connected to the adb server. Note that this state does not imply that the Android system is fully booted and operational because the device connects to adb while the system is still booting. However, after boot-up, this is the normal operational state of an device.
    • no device: There is no device connected.
  • Description: If you include the -l option, the devices command tells you what the device is. This information is helpful when you have multiple devices connected so that you can tell them apart.
The following example shows the devices command and its output. There are three devices running. The first two lines in the list are emulators, and the third line is a physical device that is attached to the computer.
$ adb devices
List of devices attached
emulator-5556 device product:sdk_google_phone_x86_64 model:Android_SDK_built_for_x86_64 device:generic_x86_64
emulator-5554 device product:sdk_google_phone_x86 model:Android_SDK_built_for_x86 device:generic_x86
0a388e93      device usb:1-1 product:razor model:Nexus_7 device:flo

Emulator not listed

The adb devices command has a corner-case command sequence that causes running emulator(s) to not show up in the adb devices output even though the emulator(s) are visible on your desktop. This happens when all of the following conditions are true:
  1. The adb server is not running, and
  2. You use the emulator command with the -port or -ports option with an odd-numbered port value between 5554 and 5584, and
  3. The odd-numbered port you chose is not busy so the port connection can be made at the specified port number, or if it is busy, the emulator switches to another port that meets the requirements in 2, and
  4. You start the adb server after you start the emulator.
One way to avoid this situation is let the emulator choose its own ports, and don't run more than 16 emulators at once. Another way is to always start the adb server before you use the emulator command, as explained in the following examples.
Example 1: In the following command sequence, the adb devices command starts the adb server, but the list of devices does not appear.
Stop the adb server and enter the following commands in the order shown. For the avd name, provide a valid avd name from your system. To get a list of avd names, type emulator -list-avds. The emulator command is in the android_sdk/tools directory.
$ adb kill-server
$ emulator -avd Nexus_6_API_25 -port 5555
$ adb devices
List of devices attached* daemon not running. starting it now on port 5037 *
* daemon started successfully *
Example 2: In the following command sequence, adb devices displays the list of devices because the adb server was started first.
To see the emulator in the adb devices output, stop the adb server, and then start it again after using the emulator command and before using the adb devices command, as follows:
$ adb kill-server
$ emulator -avd Nexus_6_API_25 -port 5557
$ adb start-server
$ adb devices
List of devices attached
emulator-5557 device

0 Reviews:

Post Your Review