Saturday, 28 December 2013

What is Android Debug Bridge (adb)?

This post is essentially dedicated to understand what Android Debug Bridge (adb) really is. How can we use it.


As we know Android has Linux kernel underneath. To execute a process via we need to provide corresponding command line command. Unless you root your android device you cannot really instal the terminal emulator application. The shell can be accessed via ADB (Android Debug Bridge) command tool.

What is Android Debug Bridge?

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.  
A client can be you adb shell that you run or your IDE(Eclipse). As for the server you can check the status, kill it or start it through ADB command line tool utility. To check the daemon process you can simply type adb in your android terminal(if rooted).

 To get the overview of ADB refer to following picture

Where can I find ADB tool utility?

You can find the adb tool in <sdk>/platform-tools/. You can download the SDK from here.

More on ADB....

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 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. 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 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 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 (or from a script).[Source]


Usage Common Usage Examples

  1.  adb device(shows all the devices with device id the adb server is connected to)
  2. adb help( Shows adb version and all possible commands)
  3. adb start-server(To start adb server if not started already)
  4. adb kill-server(To kill adb server)
  5. adb push <local> <remote>(To push a file from local machine to remote device/emulator)
  6. adb pull <remote> <local>(To get a file from remote device/emulator to local machine)
  7. adb version(Shows version number of adb running)
  8. adb reboot(Reboots the device)
  9. adb root(Restarts the adbd daemon with root priveledges)
  10. adb backup(Used to backup your device. You can backup everything with -all argument)
  11. adb restore (Restore from a backup taken earlier).
  12. adb install (Push and Install a package)
  13. adb uninstall (Uninstall a package)
  14. adb shell(get shell access to your Android device)
Note : How to completely backup your android device has been already covered in a previous post. You can go through that post.


Related Links


No comments:

Post a Comment

t> UA-39527780-1 back to top