Doc: adb intro

Aus CyanogenMod
(Weitergeleitet von Adb)
Wechseln zu: Navigation, Suche
Diese Seite enthält Bearbeitungen, die nicht zum Übersetzen freigegeben sind.

Andere Sprachen:Dänisch 96% • ‎Englisch 100% • ‎Spanisch 96% • ‎Französisch 96% • ‎Japanisch 28% • ‎Koreanisch 36% • ‎Niederländisch 28% • ‎Russisch 36% • ‎Chinese (China) 100% • ‎Chinese (Taiwan) 16%

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 typing adb 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. On newer versions of android, you can add -C (that is, adb logcat -C) to get the text to display in color.
  • 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.

On Ubuntu and other debian-based Linux distributions, ADB can be installed via the following commands from the Terminal:

sudo apt-get install android-tools-adb
sudo apt-get install android-tools-fastboot

then simply run adb <command>

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:

  1. Edit the "hidden" (starting with a period) file ~/.bashrc -- If your version of Linux supports the gedit editor, simply type gedit ~/.bashrc
  2. 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-tools directory. For example: export PATH=${PATH}:/home/user/android-sdk-linux/platform-tools/)
  3. Save the file. Then open a new Terminal. The adb command should now be available.

On Windows systems you can do the following:

  1. Righ-click on My Computer and select Properties.
  2. Choose Advanced, and click on the Environment Variables button.
  3. Navigate to System Variables and double click on Path to edit.
  4. Enter the full path to your tools folder.

error: device unauthorized

I forget where I was reading about this, but recently there is additional security that requires each device attached to your phone in USB debugging mode to be authorized on the phone (in a dialogue that appears behind the lock screen).

Simple enough to do.

"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. Check out Doc: developer options if you don’t see it.


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.

error: insufficient permissions for device or no permission

If you want to authorize the single device you should put a rule in your *udev* configuration like:

$ cat /etc/udev/rules.d/androids.rules 
SUBSYSTEM=="usb", ATTR{idVendor}=="2207", MODE="0666"

idVendor is determined by the lsusb output:

$ lsusb
Bus 002 Device 024: ID 2207:0000  

If, otherwise, you only need to access an unrecognized device once, you need to start the adb server as root.

adb kill-server
sudo adb start-server
adb devices 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: 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.