Como utilizar o 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. 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.
Installing adb & fastboot
Windows, Mac, and Linux
The best way to get adb and fastboot is to install the Android SDK directly from Google. After you install the SDK Tools, launch the SDK Manager and install the Android SDK Platform-tools package. Note that the manager automatically selects the latest Android X.x (API YY) package on launch which you can safely deselect if you are only interested in adb and fastboot. Then, by running the SDK manager periodically to check for updates, you can ensure these tools are always at the latest version.
The adb and fastboot executables will be located in the platform-tools subdirectory of the SDK Tools. You can add this directory to your system's PATH so that these tools are available from any Command Prompt or Terminal:
- Windows 7/8:
- From the desktop, right-click My Computer and select Properties
- In the System Properties window, click on the Advanced tab
- In the Advanced section, click the Environment Variables button
- In the Environment Variables window, highlight the Path variable in the Systems Variable section and click the Edit button
- Append
;<path-to-sdk>/platform-toolsto the end of the existing Path definition (the semi-colon separates each path entry)
- Ubuntu
- Add the following to
~/.profileand then logout/login:
if [ -d "<path-to-sdk>/platform-tools" ] ; then
PATH="<path-to-sdk>/platform-tools:$PATH"
fi
- Add the following to
- Mac
- Add the following to
~/.bash_profileand then logout/login:
if [ -d "<path-to-sdk>/platform-tools" ] ; then
export PATH="<path-to-sdk>/platform-tools:$PATH"
fi
- Add the following to
Ubuntu
An easy alternative to installing the SDK package as described above exists on Ubuntu and other debian-based Linux distributions. adb and fastboot can be installed via the following commands from the Terminal:
sudo apt-get install android-tools-adb
sudo apt-get install android-tools-fastboot
There is no need to manually edit your system's Path if this method is used.
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
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.
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
On Linux, you need to setup UDEV rules to allow communication via adb. You can either use the entire rules configuration from the UDEV page, or add just those rules relevant to you. If you're unsure of the vendor, idVendor can be determined with lsusb:
$ lsusb
Bus 002 Device 054: ID 0bb4:0f87 HTC (High Tech Computer Corp.)
...
In this example, 0bb4 is idVendor and 0f87 is idProduct (should you ever need it).
libncurses.so.5 64-bit troubles
Under the 64bit versions of some Ubuntu based distributions (e.g. Linux Mint 14), 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 remedy this by installing the i386 version of libncurses5. From a terminal, type:
sudo apt-get install libncurses5:i386