Android Debug Bridge (adb) is a versatile command-line tool that lets you communicate with a
device. The adb command facilitates a variety of device actions, such as installing and
debugging apps. adb provides access to a Unix shell that you can use to run a variety
of commands on a device. It is a client-server program that includes three components:
- A client, which sends commands. The client runs on your development machine. You can
invoke a client from a command-line terminal by issuing an
adbcommand. - A daemon (adbd), which runs commands on a device. The daemon runs as a background process on each device.
- A server, which manages communication between the client and the daemon. The server runs as a background process on your development machine.
adb is included in the Android SDK Platform Tools package. Download this
package with the SDK Manager, which installs
it at android_sdk/platform-tools/. If you want the standalone Android SDK
Platform Tools package, download it here.
For information on connecting a device for use over adb, including how to use the Connection
Assistant to troubleshoot common problems, see
Run apps on a hardware device.
How adb works
When you start an adb client, the client first checks whether there is an
adb server process already running. If there isn't, it starts the server process.
When the server starts, it binds to local TCP port 5037 and listens for commands sent from
adb clients.
Note: All adb clients use port 5037 to communicate
with the adb server.
The server then sets up connections to all running devices.
It locates emulators by scanning odd-numbered ports in the range
5555 to 5585, which is the range used by the first 16 emulators. Where the server finds an adb
daemon (adbd), it sets up a connection to that port.
Each emulator uses a pair of sequential ports — an even-numbered port for
console connections and an odd-numbered port for adb connections. For example:
Emulator 1, console: 5554
Emulator 1, adb: 5555
Emulator 2, console: 5556
Emulator 2, adb: 5557
and so on.
As shown, the emulator connected to adb on port 5555 is the same as the emulator
whose console listens on port 5554.
Once the server has set up connections to all devices, you can use adb commands to
access those devices. Because the server manages connections to devices and handles
commands from multiple adb clients, you can control any device from any client or
from a script.
Enable adb debugging on your device
To use adb with a device connected over USB, you must enable USB debugging in the device system settings, under Developer options. On Android 4.2 (API level 17) and higher, the Developer options screen is hidden by default. To make it visible, enable Developer options.
You can now connect your device with USB. You can verify that your device is
connected by executing adb devices from the
android_sdk/platform-tools/ directory. If connected,
you'll see the device name listed as a "device."
Note: When you connect a device running Android 4.2.2 (API level 17) or higher, the system shows a dialog asking whether to accept an RSA key that allows debugging through this computer. This security mechanism protects user devices because it ensures that USB debugging and other adb commands cannot be executed unless you're able to unlock the device and acknowledge the dialog.
For more information about connecting to a device over USB, read Run apps on a hardware device.
Connect to a device over Wi-Fi
Note: The instructions below do not apply to Wear devices running Android 11 (API level 30). See the guide to debugging a Wear OS app for more information.
Android 11 (API level 30) and higher support deploying and debugging your app wirelessly from your workstation using Android Debug Bridge (adb). For example, you can deploy your debuggable app to multiple remote devices without ever needing to physically connect your device via USB. This eliminates the need to deal with common USB connection issues, such as driver installation.
Android 17, alongside adb 37.0.0 introduces adb Wi-Fi 2.0 which solves many of the usability issues with the previous version. Notably, the device will automatically connect to the workstation when the device connects to a wireless debugging trusted network.
Before you begin using wireless debugging, do the following:
-
Ensure that your workstation and device are connected to the same wireless network.
-
Ensure that your device is running Android 11 (API level 30) or higher for phone or Android 13 (API level 33) or higher for TV and WearOS. For more information, see Check & update your Android version.
-
On your workstation, update to the latest version of the SDK Platform Tools.
To use wireless debugging, you must pair your device to your workstation using a QR code or a pairing code. Your workstation and device must be connected to the same wireless network. To pair to your device, follow these steps:
Note: You only need to pair your device to your workstation once. The device will remain paired with your workstation until you explicitly forget it or revoke adb debugging authorizations on your device. The device and the workstation will automatically connect when they are on the same network.
-
Enable developer options on your device.
-
On your device, tap Wireless debugging:
Figure 1. The Wireless debugging prompt on a Google Pixel phone. -
Allow wireless debugging on your network. Note that clicking the always allow on this network checkbox makes the network a trusted wireless debugging network. Your device will always allow wireless debugging on this network as soon as the device connects to the network.
-
On your device, select Pair using pairing code and take note of the IP address, port number, and pairing code displayed on the device.
-
On your workstation, open a terminal window and navigate to
android_sdk/platform-tools. -
On your workstation's terminal, run
adb pair ipaddr:port. Use the IP address and port number from above. -
When prompted, enter the pairing code, as shown below.
Figure 3. A message indicates that your device has been successfully paired. -
After your device is paired, verify that your device is connected. You can now use your device wirelessly similar to how you would with a USB connection.
To unpair your workstation, navigate to Wireless debugging on your device. Tap your workstation name under Paired devices and select Forget. Alternatively, you can click the Revoke adb debugging authorizations on your device Settings page to unapair your workstation and all other previously paired workstations.
-
If you want to quickly turn on and off wireless debugging, you can utilize the Quick settings developer tiles for Wireless debugging, found in Developer Options > Quick settings developer tiles.
Figure 4. The Quick settings developer tiles setting lets you quickly turn wireless debugging on and off.
Note: Android Studio users can pair their device with a QR code, select Pair device with QR code and scan the QR code obtained from the Pair devices over Wi-Fi dialog in Android Studio.
Resolve wireless connection issues
If you are having issues connecting to your device wirelessly, try the following troubleshooting steps to resolve the issue.
Check whether your workstation and device meet the prerequisites
Check that the workstation and device meet the prerequisites listed at the beginning of this section.
Check whether the adb setup on your workstation is correct
To verify that your ADB setup on your workstation is correct, open a terminal on your
workstation and enter adb server-status. Verify that the output shows the following:
-
version: "37.0.0"or higher: If this is not the case, download the latest version of the SDK Platform Tools. -
mdns_enabled: true: If this is set tofalse, then adb won't be able to automatically discover devices on your network. To resolve this issue, you must set theADB_MDNSenvironment variable to1and then restart the adb server by runningadb kill-serverand thenadb start-server. -
mdns_backend: LIBADBMDNS: If this is not the case, then adb is using an obsolete library to automatically discover devices on your network. To resolve this issue, you must set theADB_MDNS_OPENSCREENenvironment variable to0and then restart the adb server by runningadb kill-serverand thenadb start-server.
Check whether your network supports mDNS
adb relies on mDNS to automatically discover and connect to paired devices. To check whether your network supports mDNS, do the following:
-
On your device, enable wireless debugging as described in the Connect to a device over Wi-Fi section.
-
On your workstation, open a terminal and enter
adb mdns track-services --proto-text. -
Verify that the output isn't empty and contains a tls service with the IP address and port number of your device. If the output is empty, then your network does not support mDNS. Example output:
tls { service { instance: "adb-35121FDJH000R8-xyMD0H" service: "_adb-tls-connect._tcp" ipv4: "192.168.84.23" ipv6: "fe80:0:0:0:fc7a:299d:8d38:6c1c" port: 37895 product_model: "Pixel 8" build_version_sdk_full: "37.0" given_name: "sherifeid Pixel" serial: "35121FDJH000R8" mdns_service_version: "2.0" hostname: "Android_CXUKYJY1.local" } }
Check whether your device supports ADB Wi-Fi 2.0
Note: ADB Wi-Fi 2.0 is supported on Android 17 and higher.
To check whether your device supports ADB Wi-Fi 2.0, do the following:
-
On your device, enable wireless debugging as described in the Connect to a device over Wi-Fi section.
-
On your workstation, open a terminal and enter
adb mdns track-services --proto-text. -
Verify that the output contains
mdns_service_version: "2.0"or higher. If this is not the case, then your device is not running Android 17 or higher and doesn't support ADB Wi-Fi 2.0. To update to Android 17 or higher, check whether your device has any pending system updates. Check & update your Android version.
Report a new issue
If you are still having issues connecting to your device wirelessly, you can report a new issue. Please ensure that you provide the following information in your report:
- The logs from your device: Reproduce the issue and attach the device logs
- The logs from adb on your workstation:
- Set the environment variable
ADB_TRACE=all. - Restart the adb server by running
adb kill-serverand thenadb start-server. - Reproduce the issue.
- Locate the log files: Run
adb server-statusand attach the log file referenced in the outputlog_absolute_path.
- Set the environment variable
Connect wirelessly with a device after an initial USB connection (only option available on Android 10 and lower)
Note: This workflow is applicable also to Android 11 (and higher), the caveat being that it also involves an *initial* connection over physical USB.
Note: The following instructions do not apply to Wear devices running Android 10 (API level 29) or lower. See the guide about debugging a Wear OS app for more information.
adb usually communicates with the device over USB, but you can also use
adb over Wi-Fi. To connect a device running Android 10 (API level 29) or lower,
follow these initial steps over USB:
-
Connect your Android device and
adbhost computer to a common Wi-Fi network. - Connect the device to the host computer with a USB cable.
-
Set the target device to listen for a TCP/IP connection on port 5555:
adb tcpip 5555
- Disconnect the USB cable from the target device.
- Find the IP address of the Android device. For example, on a Nexus device, you can find the IP address at Settings > About tablet (or About phone) > Status > IP address.
-
Connect to the device by its IP address:
adb connect device_ip_address:5555
-
Confirm that your host computer is connected to the target device:
$ adb devices List of devices attached device_ip_address:5555 device
Note: Beware that not all access points
are suitable. You might need to use an access point
whose firewall is configured properly to support adb.
Your device is now connected to adb.
If the adb connection to your device is lost:
- Make sure that your host is still connected to the same Wi-Fi network as your Android device.
-
Reconnect by executing the
adb connectstep again. -
If that doesn't work, reset your
adbhost:adb kill-server
Then start over from the beginning.
Query for devices
Before issuing adb commands, it is helpful to know what device instances are connected
to the adb server. Generate a list of attached devices using the
devices command:
adb devices -l
In response, adb prints this status information for each device:
- Serial number:
adbcreates a string to uniquely identify the device by its port number. Here's an example serial number:emulator-5554 - State: The connection state of the device can be one of the following:
offline: The device is not connected toadbor is not responding.device: The device is connected to theadbserver. Note that this state does not imply that the Android system is fully booted and operational, because the device connects toadbwhile the system is still booting. After boot-up, this is the normal operational state of a device.no device: There is no device connected.
- Description: If you include the
-loption, thedevicescommand tells you what the device is. This information is helpful when you have multiple devices connected so that you can tell them apart.
The following example shows the devices command and its output. There are three
devices running. The first two lines in the list are emulators, and the third line is a hardware
device that is attached to the computer.
$ adb devices List of devices attached emulator-5556 device product:sdk_google_phone_x86_64 model:Android_SDK_built_for_x86_64 device:generic_x86_64 emulator-5554 device product:sdk_google_phone_x86 model:Android_SDK_built_for_x86 device:generic_x86 0a388e93 device usb:1-1 product:razor model:Nexus_7 device:flo
Emulator not listed
The adb devices command has a corner-case command sequence that causes running
emulators to not show up in the adb devices output even though
the emulators are visible on your desktop. This happens when all of the following
conditions are true:
- The
adbserver is not running. - You use the
emulatorcommand with the-portor-portsoption with an odd-numbered port value between 5554 and 5584. - The odd-numbered port you chose is not busy, so the port connection can be made at the specified port number — or, if it is busy, the emulator switches to another port that meets the requirements in 2.
- You start the
adbserver after you start the emulator.
One way to avoid this situation is to let the emulator choose its own ports and to run no more
than 16 emulators at once. Another way is to always start the adb server before you
use the emulator command, as explained in the following examples.
Example 1: In the following command sequence, the adb devices command starts
the adb server, but the list of devices does not appear.
Stop the adb server and enter the following commands in the order shown. For the AVD
name, provide a valid AVD name from your system. To get a list of AVD names, type
emulator -list-avds. The emulator command is in the
android_sdk/tools directory.
$ adb kill-server $ emulator -avd Nexus_6_API_25 -port 5555 $ adb devices List of devices attached * daemon not running. starting it now on port 5037 * * daemon started successfully *
Example 2: In the following command sequence, adb devices displays the
list of devices because the adb server was started first.
To see the emulator in the adb devices output, stop the adb server, and
then start it again after using the emulator command and before using the
adb devices command, as follows:
$ adb kill-server $ emulator -avd Nexus_6_API_25 -port 5557 $ adb start-server $ adb devices List of devices attached emulator-5557 device
For more information about emulator command-line options, see Command-Line startup options.
Send commands to a specific device
If multiple devices are running, you must specify the target device
when you issue the adb command.
To specify the target, follow these steps:
- Use the
devicescommand to get the serial number of the target. - Once you have the serial number, use the
-soption with theadbcommands to specify the serial number.- If you're going to issue a lot of
adbcommands, you can set the$ANDROID_SERIALenvironment variable to contain the serial number instead. - If you use both
-sand$ANDROID_SERIAL,-soverrides$ANDROID_SERIAL.
- If you're going to issue a lot of
In the following example, the list of attached devices is obtained, and then the serial
number of one of the devices is used to install the helloWorld.apk on that device:
$ adb devices List of devices attached emulator-5554 device emulator-5555 device 0.0.0.0:6520 device # To install on emulator-5555 $ adb -s emulator-5555 install helloWorld.apk # To install on 0.0.0.0:6520 $ adb -s 0.0.0.0:6520 install helloWorld.apk
Note: If you issue a command without specifying a target device
when multiple devices are available, adb displays an error
"adb: more than one device/emulator".
If you have multiple devices available but only one is an emulator,
use the -e option to send commands to the emulator. If there are multiple
devices but only one hardware device attached, use the -d option to send commands to
the hardware device.
Install an app
You can use adb to install an APK on an emulator or connected device
with the install command:
adb install path_to_apk
You must use the -t option with the install
command when you install a test APK. For more information,
see -t.
To install multiple APKs use install-multiple. This is useful if you download all
the APKs for a specific device for your app from the Play Console and want to install them on an
emulator or physical device.
For more information about how to create an APK file that you can install on an emulator/device instance, see Build and run your app.
Note: If you are using Android Studio, you do not need to use
adb directly to install your app on the emulator or device. Instead, Android Studio
handles the packaging and installation of the app for you.
Set up port forwarding
Use the forward command to set up arbitrary port forwarding, which
forwards requests on a specific host port to a different port on a device.
The following example sets up forwarding of host port 6100 to device port 7100:
adb forward tcp:6100 tcp:7100
The following example sets up forwarding of host port 6100 to local:logd:
adb forward tcp:6100 local:logd
This could be useful if you are trying to detemine what is being sent to a given port on the device. All received data will be written to the system-logging daemon and displayed in the device logs.
Copy files to and from a device
Use the pull and push commands to copy files to
and from a device. 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 a device.
To copy a file or directory and its sub-directories from the device, do the following:
adb pull remote local
To copy a file or directory and its sub-directories to the device, do the following:
adb push local remote
Replace local and remote with the paths to
the target files/directory on your development machine (local) and on the
device (remote). For example:
adb push myfile.txt /sdcard/myfile.txt
Stop the adb server
In some cases, you might need to terminate the adb server process and then restart
it to resolve the problem. For example, this could be the case if adb does not respond to a command.
To stop the adb server, use the adb kill-server command.
You can then restart the server by issuing any other adb command.
Issue adb commands
Issue adb commands from a command line on your development machine or from a script using the
following:
adb [-d | -e | -s serial_number] command
If there's only one emulator running or only one device connected, the adb command is
sent to that device by default. If multiple emulators are running and/or multiple devices are
attached, you need to use the -d, -e, or -s
option to specify the target device to which the command should be directed.
You can see a detailed list of all supported adb commands using the following
command:
adb --help
Issue shell commands
You can use the shell command to issue device commands through adb or to start an
interactive shell. To issue a single command, use the shell command like this:
adb [-d |-e | -s serial_number] shell shell_command
To start an interactive shell on a device, use the shell command like this:
adb [-d | -e | -s serial_number] shell
To exit an interactive shell, press Control+D or type exit.
Android provides most of the usual Unix command-line tools. For a list of available tools, use the following command:
adb shell ls /system/bin
Help is available for most of the commands via the --help argument.
Many of the shell commands are provided by
toybox.
General help applicable to all toybox commands is available via toybox --help.
With Android Platform Tools 23 and higher, adb handles arguments the same way that
the ssh(1) command does. This change has fixed a lot of problems with
command injection
and makes it possible to safely execute commands that contain shell
metacharacters,
such as adb install Let\'sGo.apk. This change means that the interpretation
of any command that contains shell metacharacters has also changed.
For example, adb shell setprop key 'two words' is now an error,
because the quotes are swallowed by the local shell, and the device sees
adb shell setprop key two words. To make the command work, quote twice,
once for the local shell and once for the remote shell, as you do with
ssh(1). For example, adb shell setprop key "'two words'"
works because the local shell takes the outer level of quoting and the device
still sees the inner level of quoting: setprop key 'two words'. Escaping is
also an option, but quoting twice is usually easier.
See also Logcat command-line tool, which is useful for monitoring the system log.
Call activity manager
Within an adb shell, you can issue commands with the activity manager (am) tool to
perform various system actions, such as start an activity, force-stop a process,
broadcast an intent, modify the device screen properties, and more.
While in a shell, the am syntax is:
am command
You can also issue an activity manager command directly from adb
without entering a remote shell. For example:
adb shell am start -a android.intent.action.VIEW
Table 1. Available activity manager commands