Android Debug Bridge

Android Debug Bridge
ANDROID DEBUG BRIDGE
by Robbie Hood
When it comes to Android modding, most novice users are confused or left wondering by reference over reference to a certain “adb”. This is specially true when you are looking up something on modding your device, or root it in particular. ADB is the wonder toy of Android and everyone seems to love it, so lets have a look at understanding what it is, why you need it and how you can get it.

WHAT IS ADB?

ADB stands for Android Debug Bridge. It comes as a part of the standard Android SDK, which you can grab here. Basically, it provides a terminal-based interface for interacting with your phone’s file system. Since Android platform is based on Linux, command-line isoften required to perform certain advanced operations on your device using root access.
While these things can be done directly on the device itself using some terminal emulator, it will be rather difficult to execute complex commands on such a small screen. ADB provides the bridge between your machine and your computer.

HOW TO INSTALL ADB?

Step 1: Installing the Android SDK
Note: At the time of updating this guide, the latest version of the Android SDK available is r8 and we shall be using it throughout the rest of the guide. The tools will work the same way however, even if you get a later version. In case of earlier versions though, the location of some of the tools was different and it is recommended that you get the latest available version.

The first step is to download the SDK. Use the link given in description and download the latest version of the Android SDK from there. There are versions available for Microsoft Windows, Linux and Mac OS X. In case of Windows, both an installer and a zip file are available but there isn’t any need to use the installer as a formal installation is not required.

Once you have downloaded the SDK, simply extract the compressed file to a location on your computer. In our case, we have extracted it to the root of our C drive and that makes C:\android-sdk-windows the installation location of the SDK. From here onwards, we shall be referring to this location as the ‘SDK folder’.

Step 2: Downloading the SDK Platform Tools
Previously, ADB used to be included in the SDK by default in the ‘tools’ sub-folder but now, it has been relocated to the ‘platform-tools’ sub-folder which needs to be downloaded as an SDK package. Fortunately, this is quite easy:
Just browse to the SDK folder and launch SDK Manager. When launching it for the first time, it will present you with a window to choose packages to install. The first option begins with ‘Android SDK Platform-tools’. Make sure it is checked, and uncheck all the other packages for now. You can check/uncheck a package by clicking on its name and then selecting the Accept/Reject radio button. Your window should look like this:

adb1.jpg

Now simply click ‘Install’ and wait till the platform tools are installed. Once the process is done, you will have a ‘platform-tools’ folder inside your SDK folder. That folder will include ADB and all its dependencies.

Step 3: Setting the Path variable
Now you have ADB installed but using it this way will require you to either use the complete path of the ADB command (C:\android-sdk-windows\platform-tools\adb) or to first change directory to the platform-tools subfolder of the SDK folder each time, and this can become quite a hassle. To make ADB along with other Android SDK tools and platform tools easily accessible from anywhere at the command line, we shall add their paths to the PATH environment variable. This method will apply to Windows users only. If you are a Linux or Mac user, add the ‘tools’ and ‘platform-tools’ sub-folders of the Android SDK to your system’s PATH variable using the standard method for your operating system.

· If you have no experience with editing system environment variables, make a System Restore point now so that you can revert back to it in case something goes wrong.
· If you are using Windows 7, right-click the ‘Computer’ icon and click ‘Properties’. Now click ‘Advanced System Settings’ from the options in the left pane to bring up the ‘System Properties’ window. Windows XP users will directly get this window when they right-click ‘My Computer’ and click ‘Properties’.
· In the ‘System Properties’ window, click the ‘Environment Variables’ button on the ‘Advanced’ tab.

adb2.jpg
· Find ‘Path’ in the ‘System variables’ section and double-click it to edit it.
· Make sure NOT to delete the existing entry in ‘Variable value’ or it will mess up things on your computer. Just add the following string to the end of it, including both the semi-colons:

This is what the example looks like before

Code:
C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Java\jdk1.6.0_23\bin;C:\Program Files (x86)\Java\jdk1.6.0_23\bin

we add this

Code:
;c:\android-sdk-windows\tools;c:\android-sdk-windows\platform-tools

If you have extracted the SDK’s contents to another directory, make sure to use that one for your PATH variable.
After adding the string, this is what the example Path variable looks like:

Code:
C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Java\jdk1.6.0_23\bin;C:\Program Files (x86)\Java\jdk1.6.0_23\bin;C:\android-sdk-windows\tools;C:\android-sdk-windows\platform-tools

Don’t worry if yours does not include some of the other text – what is important is the way the new entry should be added to the existing one, and the way the previous entries MUST be left unchanged. Notice that the semi-colons are necessary to separate each path variable entry from the next and previous ones.

Once you have added the path, your machine may require a reboot.

In case you messed up while editing the Path variable and ended up deleting the previously existing entries, just restore the System Restore point you made and retry, being more careful this time.

Step 4: Installing the USB drivers
Finally, you need to install the USB drivers. You may or may not need to perform this step, depending on your device. If you are using a device that ships with stock Android operating system such as the Nexus One, this will be necessary. In case of other devices that ship with their custom version of Android and some tools to sync the device with the PC, such as devices from HTC that ship with HTC Sync or devices by Samsung that ship with Samsung’s own software, the suitable driver for your device will be automatically installed with that software package.

· The first step will be to download the USB drivers. To do this, launch SDK Manager from the SDK folder and click on ‘Available packages’ in the left pane.
· Expand ‘Third party Add-ons’ followed by ‘Google Inc. add-ons’ and check ‘Google Usb Driver package’, as shown in this image:

adb3.jpg

· Click ‘Install Selected’ and in the window that pops up, click the ‘Accept all’ radio button followed by the ‘Install’ button. Wait patiently while the USB drivers are downloaded and installed in the Android SDK.
· The drivers for both 32 bit and 64 bit systems will now be present in the SDK folder under ‘usb_driver\x86′ and ‘usb_driver\x64′ sub-folders respectively.

Now that the USB drivers have been downloaded, you can install them to your computer as follows:

· On the device, go to home screen, press Menu, select Applications > Development, and enable USB Debugging.
· Now connect your phone to the PC via USB. New hardware installation should kick in, and it will start looking for the drivers.
· Manually point the drivers to the folder suitable for your operating system and let them install.
· Once drivers have installed, you can verify successful installation by going to Device Manager. Your phone should be showing under ‘ADB Interface’, like in this example:

adb4.jpg


HOW TO USE ADB

At this point, the setting is done. Here on you can simply use adb to manipulate your phone in whatever way you like. On Windows, the best way to do so is using command prompt. To ensure that adb has been set up properly, run command prompt and type ‘adb devices’ and hit enter. Your connected device should show up with a serial number.

adb5.jpg


NOTE: ADB IS FOR ADVANCED USERS, YOU CAN RUIN YOUR PHONE AND AS ALWAYS WE ARE NOT RESPONSIBLE FOR YOUR ACTIONS !!

LISTING OF ADB COMMANDS

The table below lists all of the supported adb commands and explains their meaning and usage
adk6.PNG

Querying for Emulator/Device Instances
Before issuing adb commands, it is helpful to know what emulator/device instances are connected to the adb server. You can generate a list of attached emulators/devices using the devices command:

adb devices

In response, adb prints this status information for each instance:

· Serial number — A string created by adb to uniquely identify an emulator/device instance by its console port number. The format of the serial number is <type>-<consolePort>. Here's an example serial number:

emulator-5554

· State — The connection state of the instance. Three states are supported:
offline— the instance is not connected to adb or is not responding.
device — the instance is now connected to the adb server. Note that this state does not imply that the Android system is fully booted and operational, since the instance connects to adb while the system is still booting. However, after boot-up, this is the normal operational state of an emulator/device instance.

The output for each instance is formatted like this:

[serialNumber] [state]

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

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

Issuing Shell Commands


Adb provides an ash shell that you can use to run a variety of commands on an emulator or device. The command binaries are stored in the file system of the emulator or device, in this location:

/system/bin/...

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:

adb [-d|-e|-s {<serialNumber>}] shell <shellCommand>

To drop into a remote shell on a emulator/device instance, use the shell command like this:

adb [-d|-e|-s {<serialNumber>}] shell

When you are ready to exit the remote shell, use CTRL+D or exit to end the shell session.

want more? click
edited by arawn

Jul 16, 2012