Doc: adb intro
Contents |
What is adb?
ADB ("adb"), or the Android Debug Bridge, is a development tool included with the Android SDK (Software Developer Kit), which allows for communication from an Android device (such as a phone or tablet) to a personal computer, and vice-versa. This communication can be made over a wifi connection. However more commonly, it is made via a USB cable. adb can also be used by developers for communicating from a computer to a virtual android machine that is also running on the computer.
adb is the "Swiss-army knife" of Android development. It provides numerous functions that can be accessed in detail via the command: adb --help
Popular adb commands
Among the most popular among CyanogenMod include the following, which can be typed from a Terminal program on the attached computer:
-
adb shell-- this command establishes a shell interface for establishing a command-line session with the device. In practical purposes, this allows a person to type "into" their devices, much as one would use a terminal program on Linux or Mac OS X computers. Individual shell commands can be sent to the device by typingadb shell <command_to_be_executed_on_the_device>
-
adb push <local> <remote>-- this command pushes a local file on the computer to a remote file on the device. You can include the full path to either the local or remote file.
-
adb pull <remote> [<local>]-- this command will pull a remote file on the device (you can include the path) to either a specified location on the computer or, if no destination is specified, to the current directory where the command was issued.
-
adb logcat-- this command allows you to view the device log in real time. It is also very useful for discovering and reporting bugs.
-
adb install <file>-- this is used to "side-load" apps (in their .apk format) to the device.
There are many more useful commands. Check out the full instruction list here.
Downloading and installing adb
Although adb can be downloaded as a simple binary executable file, perhaps the best way to get adb is to install the Android SDK directly from Google. That will ensure that, as adb is updated with the rest of the SDK, you can always have the latest version. adb will be located in the /platform-tools directory inside the SDK directory.
Secure USB Debugging (NEW in Android 4.2.2)
In Android 4.2.2 (which corresponds to CyanogenMod 10.1), Google implemented some new security features for using adb. The new "secure debugging" feature requires that you manually approve your computer for an adb connection. This approval must be done from within the device, and only after any screen lock has been bypassed.
To access your 4.2.2 or higher device via adb, you MUST ensure you are using a recently-updated Android SDK. Once the sdk (and therefore adb) has been updated, you must adb kill-server and adb start-server any existing adb daemon running on your computer. The first time you try to connect via adb, you should receive a prompt on your device to Allow usb debugging? for this device (along with an RSA fingerprint identifying the computer). You may select the Always allow from this computer check box if you want the device to remember this computer, in which case you will not be prompted again when connecting your device to that specific PC.
Troubleshooting adb
"Command not found" errors
If the adb or fastboot binary file is installed on your computer, but you see a "command not found" type of error when entering your command into the terminal, the problem may be that the /platform-tools directory (or whichever directory contains the binary) is not in the "path of execution" for your terminal session. This means that your computer doesn't know where exactly the binary is located.
The solution to this is to add the directory containing the binary to your PATH.
Linux/OS X
On most Linux/OS X systems using the Bourne Again Shell (bash), you can do the following:
- Edit the "hidden" (starting with a period) file
~/.bashrc-- If your version of Linux supports thegediteditor, simply typegedit ~/.bashrc - Next, add this line to the bottom:
export PATH=${PATH}:<sdk>/tools:<sdk>/platform-tools(Change <sdk> to the actual path to the SDK's/platform-toolsdirectory. For example:export PATH=${PATH}:/home/user/android-sdk-linux/platform-tools/) - Save the file. Then open a new Terminal. The
adbcommand should now be available.
Windows
On Windows systems you can do the following:
- Righ-click on My Computer and select Properties.
- Choose Advanced, and click on the Environment Variables button.
- Navigate to System Variables and double click on Path to edit.
- Enter the full path to your tools folder.
"Device not found" errors
Sometimes adb can't find your device. One solution is to run adb kill-server and then adb start-server as root or Administrator to restart the adb daemon with elevated privileges.
Also, you should make sure that the USB debugging or Android Debug Bridge option (this will vary depending on the version of Android) is checked in the Settings under Developer Options.
Note:
Some devices require a file at .android/adb_usb.ini be added to help your computer find the correct device. For example, the "encore" device requires that this file include a line containing 0x2080, the identification code for the device. If you have installed adb and are unable to find the device, you may wish to inquire as to whether this may be the case for your device.
libncurses.so.5 64-bit troubles
Under 64bits version of Linux Mint 14 and maybe other Debian/Ubuntu flavours adb shows the following error:
./adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
You can solve it by installing libncurses5 i386's version. Just type apt-get install libncurses5:i386 as root.