About this Article
Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device. It is a client-server program that includes three components:
You can find the adb tool in <sdk>/platform-tools/.
The server then sets up connections to all running emulator/device instances. It locates emulator/device instances by scanning odd-numbered ports in the range 5555 to 5585, the range used by emulators/devices.
Where the server finds an adb daemon, it sets up a connection to that port. Note that each emulator/device instance acquires a pair of sequential ports — an even-numbered port for console connections and an odd-numbered port for adb connections.
$adb help
device commands: adb push <local> <remote> - copy file/dir to device adb pull <remote> [<local>] - copy file/dir from device adb sync [ <directory> ] - copy host->device only if changed (-l means list but don't copy) (see 'adb help all') adb shell - run remote shell interactively adb shell <command> - run remote shell command adb emu <command> - run emulator console command adb logcat [ <filter-spec> ] - View device log adb forward <local> <remote> - forward socket connections forward specs are one of: tcp:<port> localabstract:<unix domain socket name> localreserved:<unix domain socket name> localfilesystem:<unix domain socket name> dev:<character device name> jdwp:<process pid> (remote only)
$adb -s emulator-5556 install helloWorld.apk
Note:if you issue a command without specifying a target emulator/device instance while multiple devices are available, adb generates an error.
You can use adb to copy an application from your development computer and install it on an emulator/device instance. To do so, use the install command. With the command, you must specify the path to the .apk file that you want to install:
$adb install <path_to_apk>
And then uninstall it:
$adb uninstall <path_to_apk>
You can use the adb commands pull and push to copy files to and from an emulator/device instance. Unlike the install command, which only copies an APK file to a specific location, the pull and push commands let you copy arbitrary directories and files to any location in an emulator/device instance.
$adb pull <remote> <local>
$adb push <remote> <local>
Note:In the commands, <local>
and <remote>
refer to the paths to the target files/directory on your development machine (local) and on the emulator/device instance (remote). For example:
$adb push /work/tools/adb.txt /system
$adb [-d|-e|-s <serialNumber>] shell <shell_command>
$adb [-d|-e|-s <serialNumber>] shell
The Android logging system provides a mechanism for collecting and viewing system debug output. Logs from various applications and portions of the system are collected in a series of circular buffers, which then can be viewed and filtered by the logcat command.
[adb] logcat [option] ... [filter-spec] ...
$adb logcat
$logcat
Some people will get such note when they use $adb device
List of devices attached ???????????? no permissions
$ lsusb Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 003: ID 18d1:0003 Google Inc. Bus 002 Device 002: ID 0461:4d81 Primax Electronics, Ltd Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 010: ID 0bb4:0c87 High Tech Computer Corp. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Note: And then find your USB ID.Here I can find my USB ID is Bus 001 Device 003: ID 18d1:0003 Google Inc.
$sudo vim /etc/udev/rules.d/70-android.rules
SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="0003",MODE="0666"
Note:The 18d1
and 0003
is my ID,you must add your ID.
$sudo chmod a+rx /etc/udev/rules.d/70-android.rules $sudo service udev restart
$sudo ./adb kill-server $./adb devices $./adb root