0% found this document useful (0 votes)
9 views

Android Debug Bridge (adb) _ Android Studio _ Android Developers

The Android Debug Bridge (adb) is a command-line tool that enables communication with Android devices for actions like app installation and debugging. It consists of a client, a daemon, and a server, facilitating commands and connections to devices over USB or wirelessly. Wireless debugging is supported on Android 11 and higher, allowing deployment and debugging without a physical connection, but requires initial setup and pairing between the device and workstation.

Uploaded by

cagale1502
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Android Debug Bridge (adb) _ Android Studio _ Android Developers

The Android Debug Bridge (adb) is a command-line tool that enables communication with Android devices for actions like app installation and debugging. It consists of a client, a daemon, and a server, facilitating commands and connections to devices over USB or wirelessly. Wireless debugging is supported on Android 11 and higher, allowing deployment and debugging without a physical connection, but requires initial setup and pairing between the device and workstation.

Uploaded by

cagale1502
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.

com/tools/adb

Android Debug Bridge ( ) is a versatile command-line tool that lets you communicate with
a device. The command facilitates a variety of device actions, such as installing and
debugging apps. 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 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.

is included in the Android SDK Pla�orm Tools package. Download this package with the
SDK Manager (/studio/intro/update#sdk-manager), which installs it at
. If you want the standalone Android SDK Pla�orm Tools package, download it here
(/studio/releases/pla�orm-tools).

For information on connecting a device for use over , including how to use the
Connection Assistant to troubleshoot common problems, see Run apps on a hardware
device (/studio/run/device).

When you sta� an client, the client �rst checks whether there is an server process
already running. If there isn't, it sta�s the server process. When the server sta�s, it binds to
local TCP po� 5037 and listens for commands sent from clients.

Note: All clients use po� 5037 to communicate with the server.

The server then sets up connections to all running devices. It locates emulators by scanning
odd-numbered po�s in the range 5555 to 5585, which is the range used by the �rst 16

1 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

emulators. Where the server �nds an daemon (adbd), it sets up a connection to that
po�.

Each emulator uses a pair of sequential po�s — an even-numbered po� for console
connections and an odd-numbered po� for connections. For example:

Emulator 1, console: 5554


Emulator 1, : 5555
Emulator 2, console: 5556
Emulator 2, : 5557
and so on.

As shown, the emulator connected to on po� 5555 is the same as the emulator whose
console listens on po� 5554.

Once the server has set up connections to all devices, you can use commands to
access those devices. Because the server manages connections to devices and handles
commands from multiple clients, you can control any device from any client or from a
script.

To use adb with a device connected over USB, you must enable USB debugging in the
device system se�ings, 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. (/studio/debug/dev-options#enable)

You can now connect your device with USB. You can verify that your device is connected by
executing from the 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.

2 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

For more information about connecting to a device over USB, read Run apps on a hardware
device (/studio/run/device).

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 (/training/wearables/get-sta�ed/debugging#wi�-debugging) for more
information.

Android 11 (API level 30) and higher suppo� 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.

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 (h�ps://suppo�.google.com/android/answer/7680439).

• If using the IDE, ensure that you have the latest version of Android Studio installed. You
can download it here (/studio).

• On your workstation, update to the latest version of the SDK Pla�orm Tools
(/studio/releases/pla�orm-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:

���Enable developer options (/studio/debug/dev-options#enable) on your device.

���Open Android Studio and select Pair Devices Using Wi-Fi from the run con�gurations
menu.

3 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

Figure 1. Run con�gurations menu.

The Pair devices over Wi-Fi window pops up, as shown in �gure 2.

4 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

Figure 2. Popup window to pair devices using QR code or pairing code.

���On your device, tap Wireless debugging and pair your device:

Figure 3. Screenshot of the Wireless debugging se�ing on a Google Pixel phone.

a��To pair your device with a QR code, select Pair device with QR code and scan

5 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

the QR code obtained from the Pair devices over Wi-Fi popup shown in �gure 2.

b��To pair your device with a pairing code, select Pair device with pairing code
from the Pair devices over Wi-Fi popup. On your device, select Pair using
pairing code and take note of the six-digit code provided. Once your device
appears on the Pair devices over Wi-Fi window, you can select Pair and enter
the six-digit code shown on your device.

Figure 4. Example of six-digit code entry.

���A�er your device is paired, you can a�empt to deploy your app to your device.

To pair a di�erent device or to forget the current device on your workstation, navigate
to Wireless debugging on your device. Tap your workstation name under Paired
devices and select Forget.

���If you want to quickly turn on and o� wireless debugging, you can utilize the Quick
se�ings developer tiles (/studio/debug/dev-options#general) for Wireless debugging,
found in Developer Options > Quick se�ings developer tiles.

6 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

Figure 5. The Quick se�ings developer tiles se�ing lets you quickly turn wireless
debugging on and o�.

Alternatively, to connect to your device using command line without Android Studio, follow
these steps:

���Enable developer options on your device, as described earlier.

���Enable Wireless debugging on your device, as described earlier.

���On your workstation, open a terminal window and navigate to


.

���Find your IP address, po� number, and pairing code by selecting Pair device with
pairing code. Take note of the IP address, po� number, and pairing code displayed on
the device.

���On your workstation's terminal, run . Use the IP address and


po� number from above.

7 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

���When prompted, enter the pairing code, as shown below.

Figure 6. A message indicates that your device has been successfully paired.

If you are having issues connecting to your device wirelessly, try the following
troubleshooting steps to resolve the issue.

Check that the workstation and device meet the prerequisites listed at the beginning of this
section (#connect-to-a-device-over-wi-�-android-11+).

The following is a list of current known issues with wireless debugging (with adb or Android
Studio) and how to resolve them:

• Wi-Fi is not connecting: Secure Wi-Fi networks, such as corporate Wi-Fi networks,
may block p2p connections and not let you connect over Wi-Fi. Try connecting with a
cable or another (non-corp) Wi-Fi network. Wireless connection using
over tcp/ip (following an initial USB connection) is another option, in case
reso�ing to a non-corp network is an option.

• over Wi-Fi sometimes turns o� automatically: This can happen if the device
either switches Wi-Fi networks or disconnects from the network. To resolve, re-
connect to the network.

• Device not connecting a�er pairing successfully: relies on mDNS to discover


and automatically connect to paired devices. If your network or device con�guration
does not suppo� mDNS or has disabled it, then you need to manually connect to the
device using .

8 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

Note: This work�ow 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
(/training/wearables/get-sta�ed/debugging#wi�-debugging) for more information.

usually communicates with the device over USB, but you can also use 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 host computer to a common Wi-Fi network.

 Note: Beware that not all access points are suitable. You might need to use an access point whose
�rewall is con�gured properly to suppo� .

���Connect the device to the host computer with a USB cable.

���Set the target device to listen for a TCP/IP connection on po� 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
�nd the IP address at Se�ings > About tablet (or About phone) > Status > IP

9 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

address.

���Connect to the device by its IP address:

adb connect :5555

���Con�rm that your host computer is connected to the target device:

$ adb devices
List of devices attached
:5555 device

Your device is now connected to .

If the 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 step again.

• If that doesn't work, reset your host:

adb kill-server

Then sta� over from the beginning.

Before issuing commands, it is helpful to know what device instances are connected to
the server. Generate a list of a�ached devices using the command:

10 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

adb devices -l

In response, prints this status information for each device:

• Serial number: creates a string to uniquely identify the device by its po� number.
Here's an example serial number:

• State: The connection state of the device can be one of the following:

• : The device is not connected to or is not responding.

• : The device is connected to the server. Note that this state does not
imply that the Android system is fully booted and operational, because the device
connects to while the system is still booting. A�er boot-up, this is the normal
operational state of a device.

• : There is no device connected.

• Description: If you include the option, the command tells you what the
device is. This information is helpful when you have multiple devices connected so that
you can tell them apa�.

The following example shows the command and its output. There are three devices
running. The �rst two lines in the list are emulators, and the third line is a hardware device
that is a�ached 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 d
emulator-5554 device product:sdk_google_phone_x86 model:Android_SDK_built_for_x86 device:
0a388e93 device usb:1-1 product:razor model:Nexus_7 device:flo

The command has a corner-case command sequence that causes running


emulators to not show up in the output even though the emulators are visible

11 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

on your desktop. This happens when all of the following conditions are true:

• The server is not running.

• You use the command with the or option with an odd-


numbered po� value between 5554 and 5584.

• The odd-numbered po� you chose is not busy, so the po� connection can be made at
the speci�ed po� number — or, if it is busy, the emulator switches to another po� that
meets the requirements in 2.

• You sta� the server a�er you sta� the emulator.

One way to avoid this situation is to let the emulator choose its own po�s and to run no
more than 16 emulators at once. Another way is to always sta� the server before you
use the command, as explained in the following examples.

Example 1: In the following command sequence, the command sta�s the


server, but the list of devices does not appear.

Stop the 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
. The command is in the 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, displays the list of devices


because the server was sta�ed �rst.

To see the emulator in the output, stop the server, and then sta� it again
a�er using the command and before using the command, as follows:

12 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

$ 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 sta�up
options (/studio/run/emulator-commandline#sta�up-options).

If multiple devices are running, you must specify the target device when you issue the
command. To specify the target, follow these steps:

���Use the command to get the serial number of the target.

���Once you have the serial number, use the option with the commands to specify
the serial number.

a��If you're going to issue a lot of commands, you can set the
environment variable to contain the serial number instead.

b��If you use both and , overrides .

In the following example, the list of a�ached devices is obtained, and then the serial number
of one of the devices is used to install the 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

13 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

# 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,
displays an error "adb: more than one device/emulator".

If you have multiple devices available but only one is an emulator, use the option to send
commands to the emulator. If there are multiple devices but only one hardware device
a�ached, use the option to send commands to the hardware device.

You can use to install an APK on an emulator or connected device with the
command:

adb install

You must use the option with the command when you install a test APK. For
more information, see (#-t-option).

To install multiple APKs use . This is useful if you download all the APKs
for a speci�c 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 �le that you can install on an emulator/
device instance, see Build and run your app (/studio/run).

Note: If you are using Android Studio, you do not need to use directly to install your app on the
emulator or device. Instead, Android Studio handles the packaging and installation of the app for you.

14 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

Use the command to set up arbitrary po� forwarding, which forwards requests on
a speci�c host po� to a di�erent po� on a device. The following example sets up forwarding
of host po� 6100 to device po� 7100:

adb forward tcp:6100 tcp:7100

The following example sets up forwarding of host po� 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 po� on the
device. All received data will be wri�en to the system-logging daemon and displayed in the
device logs.

Use the and commands to copy �les to and from a device. Unlike the
command, which only copies an APK �le to a speci�c location, the and
commands let you copy arbitrary directories and �les to any location in a device.

To copy a �le or directory and its sub-directories from the device, do the following:

adb pull

To copy a �le or directory and its sub-directories to the device, do the following:

15 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

adb push

Replace and with the paths to the target �les/directory on your development
machine (local) and on the device (remote). For example:

adb push myfile.txt ∕sdcard∕myfile.txt

In some cases, you might need to terminate the server process and then resta� it to
resolve the problem. For example, this could be the case if does not respond to a
command.

To stop the server, use the command. You can then resta� the server
by issuing any other command.

Issue commands from a command line on your development machine or from a script
using the following:

adb [-d | -e | -s ]

If there's only one emulator running or only one device connected, the command is sent
to that device by default. If multiple emulators are running and/or multiple devices are
a�ached, you need to use the , , or option to specify the target device to which the
command should be directed.

You can see a detailed list of all suppo�ed commands using the following command:

16 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

adb --help

You can use the command to issue device commands through or to sta� an
interactive shell. To issue a single command, use the command like this:

adb [-d |-e | -s ] shell

To sta� an interactive shell on a device, use the command like this:

adb [-d | -e | -s ] shell

To exit an interactive shell, press or type .

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 argument. Many of the shell
commands are provided by toybox (h�p://landley.net/toybox/). General help applicable to all
toybox commands is available via .

With Android Pla�orm Tools 23 and higher, handles arguments the same way that the
command does. This change has �xed a lot of problems with command injection
(h�ps://en.wikipedia.org/wiki/Code_injection#Shell_injection) and makes it possible to safely

17 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

execute commands that contain shell metacharacters


(h�ps://en.wikipedia.org/wiki/Metacharacter), such as . This change
means that the interpretation of any command that contains shell metacharacters has also
changed.

For example, is now an error, because the single quotes


( ) are swallowed by the local shell, and the device sees . To
make the command work, quote twice, once for the local shell and once for the remote shell,
as you do with . For example, .

See also Logcat command-line tool (/studio/command-line/logcat), which is useful for


monitoring the system log.

Within an shell, you can issue commands with the activity manager ( ) tool to pe�orm
various system actions, such as sta� an activity, force-stop a process, broadcast an intent,
modify the device screen prope�ies, and more.

While in a shell, the syntax is:

am

You can also issue an activity manager command directly from without entering a
remote shell. For example:

adb shell am start -a android.intent.action.VIEW

Table 1. Available activity manager commands

Command Description

18 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

Sta� an (/reference/android/app/Activity) speci�ed


by .

See the Speci�cation for intent arguments (#IntentSpec).

Options are:

• : Enable debugging.

• : Wait for launch to complete.

• : Sta� pro�ler and send results


to .

• : Like , but pro�ling stops


when the app goes idle.

• : Repeat the activity launch times. Prior to


each repeat, the top activity will be �nished.

• : Force stop the target app before sta�ing the activity.

• : Enable tracing of OpenGL functions.

• : Specify which user to run


as; if not speci�ed, then run as the current user.

Sta� the (/reference/android/app/Service) speci�ed


by .

See the Speci�cation for intent arguments (#IntentSpec).

Options are:

• : Specify which user to run


as. If not speci�ed, then run as the current user.

Force-stop everything associated with .

Kill all processes associated with . This command kills


only processes that are safe to kill and that will not impact the
user experience.

Options are:

• : Specify which
user's processes to kill. If not speci�ed, then kill all users'

19 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

processes.

Kill all background processes.

Issue a broadcast intent.


See the Speci�cation for intent arguments (#IntentSpec).

Options are:

• : Specify which
user to send to. If not speci�ed, then send to all users.

Sta� monitoring with an


(/reference/android/app/Instrumentation) instance. Typically
the target is the form
.

Options are:

• : Print raw results (otherwise decode


). Use with
to generate raw output for pe�ormance measurements.

• : Set argument to . For test


runners a common form is
.

• : Write pro�ling data to .

• : Wait for instrumentation to �nish before returning.


Required for test runners.

• : Turn o� window animations


while running.

• : Specify which user


instrumentation runs in. If not speci�ed, run in the current
user.

Sta� pro�ler on , write results to .

Stop pro�ler on .

20 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

Dump the heap of , write to .

Options are:

• : When supplying a
process name, specify the user of the process to dump. If
not speci�ed, the current user is used.

• : Dump bitmaps from graphics


memory. Optionally specify the format to dump in (PNG by
default).

• : Dump native heap instead of managed heap.

Set app to debug.

Options are:

• : Wait for debugger when app sta�s.

• : Retain this value.

Clear the package previous set for debugging with


.

Sta� monitoring for crashes or ANRs.


Options are:

• : Sta� on the given po� at crash/ANR.

Control screen compatibility


(/guide/practices/screen-compat-mode) mode of .

Override device display size. This command is helpful for


testing your app across di�erent screen sizes by mimicking a
small screen resolution using a device with a large screen, and
vice versa.
Example:

Override device display density. This command is helpful for


testing your app across di�erent screen densities by mimicking
a high-density screen environment using a low-density screen,

21 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

and vice versa.


Example:

Print the given intent speci�cation as a URI.


See the Speci�cation for intent arguments (#IntentSpec).

Print the given intent speci�cation as an URI.

See the Speci�cation for intent arguments (#IntentSpec).

For activity manager commands that take an argument, you can specify the intent
with the following options:

Show all

Specify the intent action, such as . You can declare this


only once.

Specify the intent data URI, such as . You can declare


this only once.

Specify the intent MIME type, such as . You can declare this only once.

Specify an intent category, such as .

Specify the component name with package name pre�x to create an explicit intent,
such as .

22 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

Add �ags to the intent, as suppo�ed by


(/reference/android/content/Intent#setFlags(int)) .

Add a null extra. This option is not suppo�ed for URI intents.

Add string data as a key-value pair.

Add boolean data as a key-value pair.

Add integer data as a key-value pair.

Add long data as a key-value pair.

Add �oat data as a key-value pair.

Add URI data as a key-value pair.

Add a component name, which is conve�ed and passed as a


(/reference/android/content/ComponentName) object.

Add an array of integers.

Add an array of longs.

23 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

Add an array of �oats.

Include the �ag


(/reference/android/content/Intent#FLAG_GRANT_READ_URI_PERMISSION) .

Include the �ag


(/reference/android/content/Intent#FLAG_GRANT_WRITE_URI_PERMISSION) .

Include the �ag


(/reference/android/content/Intent#FLAG_DEBUG_LOG_RESOLUTION) .

Include the �ag


(/reference/android/content/Intent#FLAG_EXCLUDE_STOPPED_PACKAGES) .

Include the �ag


(/reference/android/content/Intent#FLAG_INCLUDE_STOPPED_PACKAGES) .

Include the �ag


(/reference/android/content/Intent#FLAG_ACTIVITY_BROUGHT_TO_FRONT) .

Include the �ag


(/reference/android/content/Intent#FLAG_ACTIVITY_CLEAR_TOP) .

Include the �ag


(/reference/android/content/Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) .

24 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

Include the �ag


(/reference/android/content/Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) .

Include the �ag


(/reference/android/content/Intent#FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) .

Include the �ag


(/reference/android/content/Intent#FLAG_ACTIVITY_MULTIPLE_TASK) .

Include the �ag


(/reference/android/content/Intent#FLAG_ACTIVITY_NO_ANIMATION) .

Include the �ag


(/reference/android/content/Intent#FLAG_ACTIVITY_NO_HISTORY) .

Include the �ag


(/reference/android/content/Intent#FLAG_ACTIVITY_NO_USER_ACTION) .

Include the �ag


(/reference/android/content/Intent#FLAG_ACTIVITY_PREVIOUS_IS_TOP) .

Include the �ag


(/reference/android/content/Intent#FLAG_ACTIVITY_REORDER_TO_FRONT) .

Include the �ag


(/reference/android/content/Intent#FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) .

25 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

Include the �ag


(/reference/android/content/Intent#FLAG_ACTIVITY_SINGLE_TOP) .

Include the �ag


(/reference/android/content/Intent#FLAG_ACTIVITY_CLEAR_TASK) .

Include the �ag


(/reference/android/content/Intent#FLAG_ACTIVITY_TASK_ON_HOME) .

Include the �ag


(/reference/android/content/Intent#FLAG_RECEIVER_REGISTERED_ONLY) .

Include the �ag


(/reference/android/content/Intent#FLAG_RECEIVER_REPLACE_PENDING) .

Requires the use of and options to set the intent data and type.

You can directly specify a URI, package name, and component name when not
quali�ed by one of the preceding options. When an argument is unquali�ed, the tool
assumes the argument is a URI if it contains a ":" (colon). The tools assumes the
argument is a component name if it contains a "/" (forward-slash); otherwise it
assumes the argument is a package name.

Within an shell, you can issue commands with the package manager ( ) tool to
pe�orm actions and queries on app packages installed on the device.

26 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

While in a shell, the syntax is:

pm

You can also issue a package manager command directly from without entering a
remote shell. For example:

adb shell pm uninstall com.example.MyApp

Table 2. Available package manager commands

Command Description

Print all packages, optionally only those whose


package name contains the text in .

Options:

• : See associated �le.

• : Filter to only show disabled packages.

• : Filter to only show enabled packages.

• : Filter to only show system packages.

• : Filter to only show third-pa�y packages.

• : See the installer for the packages.

• : Include uninstalled packages.

• : The user space to query.

Print all known permission groups.

Print all known permissions, optionally only


those in .

27 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

Options:

• : Organize by group.

• : Print all information.

• : Sho� summary.

• : Only list dangerous permissions.

• : List only the permissions users will see.

List all test packages.


Options:

• : List the APK �le for the test package.

• : List test packages for


only this app.

Print all features of the system.

Print all the libraries suppo�ed by the current


device.

Print all users on the system.

Print the path to the APK of the given


.

Install a package, speci�ed by , to the


system.

Options:

• : Reinstall an existing app, keeping its


data.

• : Allow test APKs to be installed. Gradle


generates a test APK when you have only
run or debugged your app or have used the
Android Studio Build > Build APK command.
If the APK is built using a developer preview
SDK, you must include the option

28 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

(/studio/command-line/adb#-t-option) with
the command if you are installing
a test APK.

• : Specify
the installer package name.

• : Set the
install location using one of the following
values:

▪ : Use the default install location.

▪ : Install on internal device storage.

▪ : Install on external media.

• : Install package on the internal system


memory.

• : Allow version code downgrade.

• : Grant all permissions listed in the app


manifest.

• : Quickly update an installed


package by only updating the pa�s of the
APK that changed.

• : Installs enough of the


APK to launch the app while streaming the
remaining data in the background. To use
this feature, you must sign the APK, create
an APK Signature Scheme v4 �le
(/studio/command-line/apksigner#v4-
signing-enabled)
, and place this �le in the same directory as
the APK. This feature is only suppo�ed on
ce�ain devices. This option forces to
use the feature or fail if it is not suppo�ed,
with verbose information on why it failed.
Append the option to wait until the
APK is fully installed before granting access
to the APK.

prevents from
using this feature.

29 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

Removes a package from the system.


Options:

• : Keep the data and cache directories


a�er package removal.

• : Speci�es the user for


whom the package is removed.

• : Only
uninstalls if the app has the given version
code.

Delete all data associated with a package.

Enable the given package or component


(wri�en as "package/class").

Disable the given package or component


(wri�en as "package/class").

Options:

• : The user to disable.

Grant a permission to an app. On devices


running Android 6.0 (API level 23) and higher,
the permission can be any permission declared
in the app manifest. On devices running
Android 5.1 (API level 22) and lower, must be an
optional permission de�ned by the app.

Revoke a permission from an app. On devices


running Android 6.0 (API level 23) and higher,
the permission can be any permission declared
in the app manifest. On devices running
Android 5.1 (API level 22) and lower, must be an
optional permission de�ned by the app.

Change the default install location. Location


values:

30 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

• : Auto: Let system decide the best


location.

• : Internal: Install on internal device storage.

• : External: Install on external media.

 Note: This is only intended for debugging.


Using this can cause apps to break and other
undesireable behavior.

Returns the current install location. Return


values:
• : Let system decide the best
location

• : Install on internal device


storage

• : Install on external media

Specify whether the given permission should


be enforced.

Trim cache �les to reach the given free space.

Create a new user with the given ,


printing the new user identi�er of the user.

Remove the user with the given ,


deleting all data associated with that user

Print the maximum number of users suppo�ed


by the device.

Print the domain veri�cation state for the given


package, or for all packages if none is
speci�ed. State codes are de�ned as follows:

• : nothing has been recorded for this

31 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

domain

• : the domain has been


successfully veri�ed

• : force-approved, usually through


shell

• : force-denied, usually through shell

• : preserved veri�cation from a


legacy response

• : preserved veri�cation from a


user data restore

• : rejected by a legacy
veri�er, unknown reason

• : automatically
approved by the device con�g

• : custom error code, which is


speci�c to the device veri�er

Options are:

• : include user selections.


Include all domains, not just autoVerify
ones.

Reset domain veri�cation state for the given


package, or for all packages if none is
speci�ed.

• : the package to reset, or "all" to


reset all packages

Options are:

• : include user selections.


Include all domains, not just autoVerify
ones.

Broadcast a veri�cation request for the given


package, or for all packages if none is
speci�ed. Only sends if the package has
previously not recorded a response.

32 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

• : send even if the package


has recorded a response

Manually set the state of a domain for a


package. The domain must be declared by the
package as autoVerify for this to work. This
command will not repo� a failure for domains
that could not be applied.

• : the package to set,


or "all" to set all packages

• : the code to set the domains to. Valid


values are:

• : reset as
if no response was ever recorded.

• : treat domain
as successfully veri�ed by domain
veri�cation agent. Note that the
domain veri�cation agent can
override this.

• : treat domain
as always approved, preventing the
domain veri�cation agent from
changing it.

• : treat domain as
always denied, preventing the domain
veri�cation agent from changing it.

• : space-separated list of domains


to change, or "all" to change every domain.

Manually set the state of a host user selection


for a package. The domain must be declared
by the package for this to work. This command
will not repo� a failure for domains that could
not be applied.

• : the user to change


selections for

• : the package to set

33 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

• : whether to approve the domain

• : space-separated list of domains


to change, or "all" to change every domain

Manually set the state of a host user selection


for a package. The domain must be declared
by the package for this to work. This command
will not repo� a failure for domains that could
not be applied.

• : the user to change


selections for

• : the package to set

• : whether to approve the domain

• : space-separated list of domains


to change, or "all" to change every domain

Toggle the auto-veri�ed link-handling se�ing


for a package.

• : the user to change


selections for

• : the package to set,


or "all" to set all packages; packages will be
reset if no package is speci�ed

• : true to allow the package to open


auto-veri�ed links, false to disable

Print the owners for a speci�c domain for a


given user in low- to high-priority order.

• : the user to query for

• : optionally also print


for all web domains declared by a package,
or "all" to print all packages

• : space-separated list of domains


to query for

34 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

To help you develop and test your device management apps, issue commands to the device
policy manager ( ) tool. Use the tool to control the active admin app or change a policy's
status data on the device.

While in a shell, the syntax is:

dpm

You can also issue a device policy manager command directly from without entering a
remote shell:

adb shell dpm

Table 3. Available device policy manager commands

Command Description

Sets component as active admin.

Options are:

• : Specify the target user. You can also pass


to select the current user.

Set component as active admin and its package as pro�le owner f


existing user.

Options are:

• : Specify the target user. You can also pass


to select the current user.

• : Specify the human-readable organization name

35 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

Set component as active admin and its package as device owner.

Options are:

• : Specify the target user. You can also pass


to select the current user.

• : Specify the human-readable organization name

Disable an active admin. The app must declare


(/guide/topics/manifest/application-element#testOnly
This command also removes device and pro�le owners.

Options are:

• : Specify the target user. You can also pass


to select the current user.

Clear the device's record of previously set freeze periods for syste
updates. This is useful to avoid the device scheduling restrictions
developing apps that manage freeze periods. See Manage system
updates (/work/dpc/system-updates#development_and_testing

Suppo�ed on devices running Android 9.0 (API level 28) and highe

Force the system to make any existing network logs ready for retri
a DPC. If there are connection or DNS logs available, the DPC rece
the
(/reference/android/app/admin/
DeviceAdminReceiver#onNetworkLogsAvailable(android.content.C
%20android.content.Intent,%20long,%20int))
callback. See Network activity logging
(/work/dpc/logging#development_and_testing).

This command is rate-limited. Suppo�ed on devices running Andro


(API level 28) and higher.

Force the system to make any existing security logs available to th


If there are logs available, the DPC receives the

(/reference/android/app/admin/
DeviceAdminReceiver#onSecurityLogsAvailable(android.content.C
%20android.content.Intent))
callback. See Log enterprise device activity

36 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

(/work/dpc/security#log_enterprise_device_activity).

This command is rate-limited. Suppo�ed on devices running Andro


(API level 28) and higher.

The command is a shell utility for taking a screenshot of a device display.

While in a shell, the syntax is:

screencap

To use from the command line, enter the following:

adb shell screencap ∕sdcard∕screen.png

Here's an example screenshot session, using the shell to capture the screenshot and
the command to download the �le from the device:

$ adb shell
shell@ $ screencap ∕sdcard∕screen.png
shell@ $ exit
$ adb pull ∕sdcard∕screen.png

The 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 �le.
You can use this �le to create promotional or training videos or for debugging and testing.

37 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

In a shell, use the following syntax:

screenrecord [ ]

To use from the command line, enter the following:

adb shell screenrecord ∕sdcard∕demo.mp4

Stop the screen recording by pressing Control+C. Otherwise, the recording stops
automatically at three minutes or the time limit set by .

To begin recording your device screen, run the command to record the video.
Then, run the 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 utility can record at any suppo�ed 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.

Limitations of the utility:

• Audio is not recorded with the video �le.

• Video recording is not available for devices running Wear OS.

• Some devices might not be able to record at their native display resolution. If you

38 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

encounter problems with screen recording, try using a lower screen resolution.

• Rotation of the screen during recording is not suppo�ed. If the screen does rotate
during recording, some of the screen is cut o� in the recording.

Table 4. options

Options Description

Display command syntax and options

Set the video size: . The default value is the device's native display
resolution (if suppo�ed), 1280x720 if not. For best results, use a size suppo�ed
by your device's Advanced Video Coding (AVC) encoder.

Set the video bit rate for the video, in megabits per second. The default value is
20Mbps. You can increase the bit rate to improve video quality, but doing so
results in larger movie �les. The following example sets the recording bit rate to
6Mbps:
screenrecord --bit-rate 6000000 ∕sdcard∕demo.mp4

Set the maximum recording time, in seconds. The default and maximum value is
180 (3 minutes).

Rotate the output 90 degrees. This feature is experimental.

Display log information on the command-line screen. If you do not set this
option, the utility does not display any information while running.

Sta�ing in Android 7.0 (API level 24), the Android Runtime (ART) collects execution pro�les
for installed apps, which are used to optimize app pe�ormance. Examine the collected
pro�les to understand which methods are executed frequently and which classes are used
during app sta�up.

Note: It is only possible to retrieve the execution pro�le �lename if you have root access to the �le

39 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

system, for example, on an emulator.

To produce a text form of the pro�le information, use the following command:

adb shell cmd package dump-profiles

To retrieve the �le produced, use:

adb pull ∕data∕misc∕profman∕ .prof.txt

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
pe�orm a factory reset of a test device running Android 10 (API level 29) or higher using the
shell command, as shown:

adb shell cmd testharness enable

When restoring the device using , the device automatically backs up the RSA
key that allows debugging through the current workstation in a persistent location. That is,
a�er the device is reset, the workstation can continue to debug and issue 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
to restore a device also changes the following device se�ings:

• The device sets up ce�ain system se�ings 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.

40 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

• Se�ings:

• Disables lock screen.

• Disables emergency ale�s.

• Disables auto-sync for accounts.

• Disables automatic system updates.

• Other:

• Disables preinstalled security apps.

If your app needs to detect and adapt to the default se�ings of the command,
use the
(/reference/android/app/ActivityManager#isRunningInUserTestHarness()).

sta�s the command-line program for examining SQLite databases. It


includes commands such as to print the contents of a table and to print the
statement for an existing table. You can also execute SQLite commands from
the command line, as shown:

$ adb -s emulator-5554 shell


$ sqlite3 ∕data∕data∕com.example.app∕databases∕rssitems.db
SQLite version 3.3.12
Enter ".help" for instructions

Note: It is only possible to access a SQLite database if you have root access to the �le system, for
example, on an emulator.

For more information, see the command line documentation


(h�p://www.sqlite.org/cli.html).

41 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

The adb server can interact with the USB stack through two backends. It can either use the
native backend of the OS (Windows, Linux, or macOS) or it can use the backend.
Some features, such as , , and USB speed detection, are only available when
using backend.

You can choose a backend by using the environment variable. If it isn't set, adb
uses its default backend. The default behavior varies among OS. Sta�ing with ADB v34
(h�ps://developer.android.com/tools/releases/pla�orm-tools#revisions), the backend is
used by default on all OS except Windows, where the native backend is used by default. If
is set, it determines whether the native backend or is used. See the adb
manual page
(h�ps://android.googlesource.com/pla�orm/packages/modules/adb/+/refs/heads/master/docs/user/
adb.1.md)
for more information about adb environment variables.

Experimental: Suppo� for using the backend with Windows is experimental. As of ADB v34, only
the macOS and Linux pla�orms have been tested with the library.

ADB can use the multicast DNS protocol to automatically connect the server and devices.
The ADB server ships with two backends, Bonjour (Apple's mdnsResponder) and
Openscreen.

The Bonjour backend needs a daemon to be running on the host machine. On macOS
Apple's built-in daemon is always running, but on Windows and Linux, the user must make
sure the daemon is up and running. If the command returns an error,
it is likely that ADB is using the Bonjour backend but there is no Bonjour daemon running.

The Openscreen backend does not need a daemon to be running on the machine. Suppo�
for the Openscreen backend on macOS sta�s at ADB v35. Windows and Linux are
suppo�ed as of ADB v34.

By default ADB uses the Bonjour backend. This behavior can be changed using the

42 of 43 8/14/24, 23:48
Android Debug Bridge (adb) | Android Studio | Andro... https://developer.android.com/tools/adb

environment variable (set to or ). See the ADB manual page


(h�ps://android.googlesource.com/pla�orm/packages/modules/adb/+/refs/heads/master/docs/user/
adb.1.md)
for fu�her details.

Content and code samples on this page are subject to the licenses described in the Content License (/license).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its a�liates.

Last updated 2024-07-31 UTC.

43 of 43 8/14/24, 23:48

You might also like