adb

From CyanogenMod
Jump to: navigation, search
This page is a translated version of a page Doc: adb intro and the translation is 16% complete.

Other languages:Danish 96% • ‎English 100% • ‎Spanish 96% • ‎French 96% • ‎Japanese 28% • ‎Korean 36% • ‎Dutch 28% • ‎Russian 36% • ‎Chinese (China) 100% • ‎Chinese (Taiwan) 16%

什麼是 adb?

ADB ("adb",Android 除錯橋)是一個開發工具,包含著Android SDK,並且允許從 Android 裝置連線 (可能手機或平板) 到一個個人電腦,普遍都透過 USB、網路連線。adb 也可以從電腦連線到一個虛擬 Android 機器,該虛擬機器同樣也執行於電腦上。

adb 是一個 Android 開發中的「瑞士軍刀 (Swiss-army knife)」。它提供了眾多功能,您可以存取它們。列出所有指令,輸入: 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 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:

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

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.

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