This guide describes how to perform common tasks using ADB.
Android Debug Bridge (ADB) is included in the Android SDK and is the main tool used to communicate with an Android device for debugging. The official documentation for ADB can be found at https://developer.android.com/studio/command-line/adb.
Windows users must install the appropriate device drivers to use ADB. See Device Setup for more information.
For a list of available commands and options, enter the following from a command line:
From the OS shell, it is possible to connect to and communicate with an Android device either directly through USB, or via TCP/IP over a Wi-Fi connection.
To connect a device via USB, plug the device into the PC with a compatible USB cable. After connecting, open up an OS shell and type:
If the device is connected properly, ADB will show the device id list such as:
List of devices attached ce0551e7 device
ADB can’t be used if no device is detected. If your device is not listed, the most likely problem is that you do not have the correct USB driver (see Device Setup for more information). You may also wish to try another USB cable and/or port.
Connecting to a device via USB is generally faster than using a TCP/IP connection, but a TCP/IP connection is sometimes indispensable.
To connect via TCP/IP, first make sure the device is already connected via USB, and then use this command to determine its IP address:
adb shell ip route
The output should look something like this:
10.0.30.0/19 dev wlan0 proto kernel scope link src 10.0.32.101
The IP address of the device follows
src. Using the IP address and port (generally 5555), issue the following commands:
adb tcpip <port> adb connect <ipaddress>:<port>
> adb tcpip 5555 restarting in TCP mode port: 5555 > adb connect 10.0.32.101:5555 connected to 10.0.32.101:5555
The device can now be disconnected from the USB port. As long as
adb devices shows only a single device, all ADB commands will be issued for the device via Wi-Fi.
To stop using the Wi-Fi connection, issue the following ADB command from the OS shell:
To install an APK on your mobile device using ADB, connect to the target device and verify connection using ADB devices as described above. Then install the APK with the following command:
adb install <apk-path>
-r option to overwrite an existing APK of the same name already installed on the target device. For example:
adb install -r C:\Dev\Android\MyProject\VrApp.apk
For more information, see the Installing an Application section of Android’s Android Debug Bridge guide.
Note that depending on the particular device, detection may be finicky from time to time. In particular, on some devices, connecting while a VR app is running or when ADB is waiting for a device may prevent the device from being reliably detected. In those cases, try ending the app and stopping ADB using Ctrl-C before reconnecting the device. Alternatively, the ADB service can be stopped using the following command, after which the ADB service will automatically be restarted when executing the next command:
Multiple devices may be attached at once, and this is often valuable for debugging client/server applications. Be aware that when the same device is simultaneously connected by Wi-Fi and USB, ADB will show the device as two devices. When there are multiple listed devices, ADB must be told which device to target using the
-s switch. For example, consider if
adb devices showed the following:
List of devices attached ce0551e7 device 10.0.32.101:5555 device
The listed devices could be two separate devices, or one device that is connected both via Wi-Fi and plugged into USB (perhaps to charge the battery). In this case, all ADB commands must take the following form, where <device id> is the identifier reported by
adb -s <device id> <command>
For example, to issue a logcat command to the device connected via TCP/IP:
adb -s 10.0.32.101:5555 logcat -c
To issue the same command to the device connected via USB:
adb -s ce0551e7