ADB(Android Debug Bridge)

Posted: August 30, 2012 in Android
Tags: ,

Android Debug Bridge:
Android Debug Bridge (adb) is a command line tool that lets you communicate with an emulator or connected Android device. It is a client-server program that includes three components:

  • Client- It runs on your development machine. You can invoke a client from a shell by issuing an adb command.
  • Server-It runs as a background process on your development machine. The server manages communication between the client and the adb daemon.
  • Daemon- It runs as a background process on each emulator or device instance.

ADB is found as part of the Andriod SDk Platform-tools package, it consists of both client and server-side programs that communicate with one another.

When you start an adb client, first checks whether there is an adb server process already running. If there is no adb running process, it starts the server process. When server starts, it binds to local TCP port and listens the adb commands. 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.

ADB Commands:
The format for issuing commands through the ADB is as follows:
adb [-d|-e|-s <serialNumber>] <command>

Installing an Application:
With the help of adb we can install our app on emulator or device.
adb install <path_to_apk>
where <path_to_apk> is the path of that apk file which you want to install on emulator/device.

Viewing connected Android devices:
To view the attached devices use devices command. It prints a list of all attached emulator/device instances.
adb devices
Here’s an example showing the devices command and its output:
$ adb devices
List of devices attached
emulator-5554 device
emulator-5556 device
emulator-5558 device
where emulator-5558 is the serial number and device is the instance that is connected to adb server.

If there is no emulator/device running, adb returns no device.

Sending commands to specific emulator/device:
If multiple emulator/device instances are running, you need to specify a target instance when issuing adb commands.
adb -s <serialNumber> <command>
Example: adb -s emulator-5556 install demo1.apk

Copying Files to or from an Emulator/Device :

You can use the adb commands pull and push to copy files to and from an emulator/device.

If you want to copy a file from the emulator or device you can use pull command.
adb pull <remote> <local>

If you want to copy a file to  the emulator or device you can use push command.
adb push <local> <remote>

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).

Starting and killing the server:

To start server use,
adb start-server
When the server starts, it binds to local TCP port 5037. All adb clients use port 5037 to communicate with the adb server.

To kill server use kill-server command it kills the already running server.
adb kill-server

Forwarding Ports:
Forward command is used to forward the requests on the specific host port to a different port on emulator/device instance.
adb forward tcp:6100 tcp:7100

Enabling logcat Logging
You can use the logcat command to view log output in your development computer.
adb logcat

Advertisements
Comments
  1. I’m very happy to uncover this site. I need to to thank you for ones time for this wonderful read!! I definitely savored every part of it and i also have you bookmarked to look at new information on your web site.

  2. App Apk says:

    Hey there! I could have sworn I’ve been to this website before but after checking
    through some of the post I realized it’s new to me. Anyhow, I’m definitely
    delighted I found it and I’ll be bookmarking and checking back frequently!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s