Android Debug Bridge (Adb)
Android Debug Bridge (Adb)
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, and it 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 adb
command.
• 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. You can download this
package with the SDK Manager, which installs it at android_sdk/platform-tools/. Or if you
want the standalone Android SDK Platform-Tools package, you can 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.
The server then sets up connections to all running devices. It locates emulators by
scanning odd-numbered ports in the range 5555 to 5585, the range used by the first 16
emulators. Where the server finds an adb daemon (adbd), it sets up a connection to that
port. Note that 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:
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).
On Android 4.2 and higher, the Developer options screen is hidden by default. To make
it visible, go to Settings > About phone and tap Build number seven times. Return to the
previous screen to find Developer options at the bottom.
On some devices, the Developer options screen might be located or named differently.
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 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.
Android 11 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 physically connecting your device
via USB. This eliminates the need to deal with common USB connection issues, such as
driver installation.
Before you begin using wireless debugging, you must complete the following steps:
1. Ensure that your workstation and device are connected to the same wireless
network.
2. Ensure that your device is running Android 11 or higher. For more informaton,
see Check & update your Android version.
3. Ensure that you have Android Studio Bumblebee. You can download it here.
4. 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 connect to your device, follow these steps:
Device Setting
Device Setting
Google Pixel, OnePlus 5T and later Settings > System > Dev
Samsung Galaxy S8 and later, LG G6 and later, HTC U11 and later Settings > Developer op
b. In Developer options, scroll down to the Debugging section and turn
on Wireless debugging. On the Allow wireless debugging on this
network? popup, select Allow.
3. Open Android Studio and select Pair Devices Using Wi-Fi from the run
configurations dropdown menu.
Figure 1. Run configurations dropdown menu.
The Pair devices over Wi-Fi window pops up, as shown below.
adb usually communicates with the device over USB, but you can also use adb over Wi-
Fi. To connect a device running Android 10 or lower, there are some initial steps you
must do over USB, as described below:
1. Connect your Android device and adb host computer to a common Wi-Fi network
accessible to both. Beware that not all access points are suitable; you might
need to use an access point whose firewall is configured properly to support adb.
2. If you are connecting to a Wear OS device, turn off Bluetooth on the phone that's
paired with the device.
3. Connect the device to the host computer with a USB cable.
4. Set the target device to listen for a TCP/IP connection on port 5555.
10. Confirm that your host computer is connected to the target device:
11. $ adb devices
12. List of devices attached
13. device_ip_address:5555 device
1. Make sure that your host is still connected to the same Wi-Fi network your
Android device is.
2. Reconnect by executing the adb connect step again.
3. Or if that doesn't work, reset your adb host:
4. adb kill-server
adb devices -l
• Serial number: A string created by adb 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 to adb or is not responding.
• device: The device is now connected to the adb server. Note that this state
does not imply that the Android system is fully booted and operational
because the device connects to adb while the system is still booting.
However, after boot-up, this is the normal operational state of an device.
• no device: There is no device connected.
• Description: If you include the -l option, the devices command 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
The adb devices command has a corner-case command sequence that causes running
emulator(s) to not show up in the adb devices output even though the emulator(s) are
visible on your desktop. This happens when all of the following conditions are true:
One way to avoid this situation is to let the emulator choose its own ports, and don't run
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
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
For more information about emulator command-line options, see Using Command Line
Parameters.
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
Note: If you issue a command without specifying a target device when multiple devices are
available, adb generates an error.
If you have multiple devices available, but only one is an emulator, use the -e option to
send commands to the emulator. Likewise, 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:
You must use the -t option with the install command when you install a test APK. For
more information, see -t.
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 that, if you are using Android Studio, you do not need to use adb directly to install
your app on the emulator/device. Instead, Android Studio handles the packaging and
installation of the app for you.
To copy a file or directory and its sub-directories from the device, do the following:
To copy a file or directory and its sub-directories to the device, do the following:
To stop the adb server, use the adb kill-server command. You can then restart the server
by issuing any other adb 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
To start an interactive shell on a device use the shell command like this:
Note: 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 now safely execute commands that contain shell metacharacters, such as adb
install Let\'sGo.apk. But, this change means that the interpretation of any command that
contains shell metacharacters has also changed. For example, the adb shell setprop foo 'a
b' command is now an error because the single quotes (') are swallowed by the local shell, and the
device sees adb shell setprop foo a b. To make the command work, quote twice, once for the
local shell and once for the remote shell, the same as you do with ssh(1). For example, adb shell
setprop foo "'a b'".
Android provides most of the usual Unix command-line tools. For a list of available
tools, use the following command:
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.
See also Logcat Command-Line Tool which is useful for monitoring the system log.
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
syntax is:
am command
You can also issue an activity manager command directly from adb without entering a
remote shell. For example:
Command Description
Options are:
• -R count: Repeat the activity launch count times. Prior to each repeat, the top activity
• -S: Force stop the target app before starting the activity.
• --user user_id | current: Specify which user to run as; if not specified, then run as th
startservice [options] intent Start the Service specified by intent.
Options are:
• --user user_id | current: Specify which user to run as; if not specified, then run as th
force-stop package Force stop everything associated with package (the app's package name).
kill [options] package Kill all processes associated with package (the app's package name). This command kills onl
safe to kill and that will not impact the user experience.
Options are:
• --user user_id | all | current: Specify user whose processes to kill; all users if not spe
kill-all Kill all background processes.
broadcast [options] intent Issue a broadcast intent.
See the Specification for intent arguments.
Options are:
• [--user user_id | all | current]: Specify which user to send to; if not specified then se
instrument [options] component Start monitoring with an Instrumentation instance. Typically the target component is the
form test_package/runner_class.
Options are:
• -r: Print raw results (otherwise decode report_key_streamresult). Use with [-e perf t
output for performance measurements.
• -e name value: Set argument name to value. For test runners a common form is -
e testrunner_flag value[,value...].
• -w: Wait for instrumentation to finish before returning. Required for test runners.
Options are:
• --user [user_id | current]: When supplying a process name, specify user of process t
user if not specified.
Options are:
For activity manager commands that take an intent argument, you can specify the intent
with the following options:
Show all
Within an adb shell, you can issue commands with the package manager (pm) tool to
perform actions and queries on app packages installed on the device. While in a shell,
the syntax is:
pm command
You can also issue a package manager command directly from adb without entering a
remote shell. For example:
Command Description
list packages [options] filter Prints all packages, optionally only those whose package name contains the tex
Options:
Options:
Options:
• -t: Allow test APKs to be installed. Gradle generates a test APK when
debugged your app or have used the Android Studio Build > Build APK
APK is built using a developer preview SDK (if the targetSdkVersion
number), you must include the -t option with the install command if yo
APK.
• --incremental: Installs enough of the APK to launch the app while stre
data in the background. To use this feature, you must sign the APK, cre
Scheme v4 file, and place this file in the same directory as the APK. Th
supported on certain devices. This option forces adb to use the feature
supported (with verbose information on why it failed). Append the --w
the APK is fully installed before granting access to the APK.
• -k: Keep the data and cache directories around after package removal.
clear package Deletes all data associated with a package.
enable package_or_component Enable the given package or component (written as "package/class").
disable package_or_component Disable the given package or component (written as "package/class").
disable-user [options] package_or_component Options:
Note: This is only intended for debugging; using this can cause apps to break an
behavior.
get-install-location Returns the current install location. Return values:
• 0 [auto]: Lets system decide the best location
dpm command
You can also issue a device policy manager command directly from adb without
entering a remote shell:
Command Description
Options are:
• --user user_id: Specify the target user. You can also pass --user current to
user.
set-profile-owner [options] component Sets component as active admin and its package as profile owner for an existing use
Options are:
• --user user_id: Specify the target user. You can also pass --user current to
user.
Options are:
• --user user_id: Specify the target user. You can also pass --user current to
user.
Options are:
• --user user_id: Specify the target user. You can also pass --user current to
user.
clear-freeze-period-record Clears the device's record of previously-set freeze periods for system OTA updates
the device's scheduling restrictions when developing apps that manage freeze-perio
updates.
Supported on devices running Android 9.0 (API level 28) and higher.
force-network-logs Forces the system to make any existing network logs ready for retrieval by a DPC.
or DNS logs available, the DPC receives the onNetworkLogsAvailable() callback.
logging.
This command is rate-limited. Supported on devices running Android 9.0 (API leve
force-security-logs Forces the system to make any existing security logs available to the DPC. If there
DPC receives the onSecurityLogsAvailable() callback. See Log enterprise device
This command is rate-limited. Supported on devices running Android 9.0 (API leve
Take a screenshot
The screencap command is a shell utility for taking a screenshot of a device display.
While in a shell, the syntax is:
screencap filename
To use the screencap from the command line, type the following:
Here's an example screenshot session, using the adb shell to capture the screenshot
and the pull command to download the file from the device:
$ adb shell
shell@ $ screencap /sdcard/screen.png
shell@ $ exit
$ adb pull /sdcard/screen.png
Record a video
The screenrecord command is a shell utility for recording the display of devices running
Android 4.4 (API level 19) and higher. The utility records screen activity to an MPEG-4
file. You can use this file to create promotional or training videos or for debugging and
testing.
To begin recording your device screen, run the screenrecord command to record the
video. Then, run the pull command to download the video from the device to the host
computer. Here's an example recording session:
$ adb shell
shell@ $ screenrecord --verbose /sdcard/demo.mp4
(press Control + C to stop)
shell@ $ exit
$ adb pull /sdcard/demo.mp4
The screenrecord utility can record at any supported resolution and bit rate you request,
while retaining the aspect ratio of the device display. The utility records at the native
display resolution and orientation by default, with a maximum length of three minutes.
Options Description
Starting in Android 7.0 (API level 24) the Android Runtime (ART) collects execution
profiles for installed apps, which are used to optimize app performance. You might
want to examine the collected profiles to understand which methods are determined to
be frequently executed and which classes are used during app startup.
If you test your app across multiple test devices, it may be useful to reset your device
between tests, for example, to remove user data and reset the test environment. You
can perform a factory reset of a test device running Android 10 (API level 29) or higher
using the testharness adb shell command, as shown below.
When restoring the device using testharness, the device automatically backs up the RSA
key that allows debugging through the current workstation in a persistent location. That
is, after the device is reset, the workstation can continue to debug and issue adb
commands to the device without manually registering a new key.
Additionally, to help make it easier and more secure to keep testing your app, using
the testharness to restore a device also changes the following device settings:
• The device sets up certain system settings so that initial device setup wizards do
not appear. That is, the device enters a state from which you can quickly install,
debug, and test your app.
• Settings:
• Disables lock screen
• Disables emergency alerts
• Disables auto-sync for accounts
• Disables automatic system updates
• Other:
• Disables preinstalled security apps
If you app needs to detect and adapt to the default settings of the testharness command,
you can use the ActivityManager.isRunningInUserTestHarness().
sqlite
sqlite3 starts the sqlite command-line program for examining sqlite databases. It
includes commands such as .dump to print the contents of a table, and .schema to print
the SQL CREATE statement for an existing table. You can also execute SQLite commands
from the command line, as shown below.