adb
Debug and interact with Android devices
TLDR
Check whether the adb server process is running and start it
Terminate the adb server process
Start a remote shell in the target emulator/device instance
Push an Android application to an emulator/device
Copy a file/directory from the target device
Copy a file/directory to the target device
List all connected devices
Specify which device to send commands to if there are multiple devices
SYNOPSIS
adb [global options] command [command options] arguments
Global Options:
-d: Directs command to the only USB device connected.
-e: Directs command to the only running emulator instance.
-s SERIAL: Directs command to the device or emulator with the given serial number.
-t TRANSPORT_ID: Directs command to the device with the given transport ID.
-P PORT: Specifies the port number for the adb server.
-H HOST: Specifies the address of the adb server (default is localhost).
PARAMETERS
-d
Directs command to the only USB device connected.
-e
Directs command to the only running emulator instance.
-s SERIAL
Directs command to the device or emulator with the given serial number.
-t TRANSPORT_ID
Directs command to the device with the given transport ID.
-P PORT
Specifies the port number for the adb server (default 5037).
-H HOST
Specifies the address of the adb server (default is localhost).
devices
Lists all connected devices and emulators.
install PATH_TO_APK
Installs an Android application package (APK) on the device. Common options include -r (reinstall) and -g (grant all permissions).
uninstall PACKAGE_NAME
Removes an Android application from the device. Use -k to keep the data and cache directories.
push LOCAL REMOTE
Copies a file or directory from the host machine to the device.
pull REMOTE LOCAL
Copies a file or directory from the device to the host machine.
shell [command]
Starts a remote shell on the device, or executes a single command on the device.
logcat [options]
Displays device log messages in real-time. Use -c to clear logs, -d to dump and exit, -s to filter by tag.
reboot [bootloader|recovery|sideload]
Reboots the device into the Android system, bootloader, recovery, or sideload mode.
connect HOST[:PORT]
Connects to a device via TCP/IP (usually after enabling wireless debugging).
disconnect [HOST[:PORT]]
Disconnects from a specified TCP/IP device or all connected devices.
sideload OTA_UPDATE.zip
Starts the device in sideload mode to install an OTA update package from a zip file.
DESCRIPTION
adb (Android Debug Bridge) is a versatile command-line tool that lets you communicate with an Android-powered device. It's a client-server program that includes three components: a client, a daemon (adbd), and a server. The client runs on your development machine, the daemon runs as a background process on each connected device, and the server runs as a background process on your development machine to manage communication between the client and the daemon.
adb provides various functionalities crucial for Android app development and debugging. It enables you to install and uninstall applications, copy files to and from the device, access the device's shell (running commands directly on the Android system), view system logs (logcat), and control the device's state (e.g., reboot, boot into recovery). It's an essential tool for developers, testers, and power users alike, offering deep access and control over Android devices via USB or network connections.
CAVEATS
Using adb requires USB debugging to be enabled on the Android device, which can pose a security risk if the device falls into unauthorized hands, as it allows deep system access. On Windows, proper USB drivers for the specific Android device are often necessary and can be a common source of connectivity issues. Misuse of powerful adb commands, especially those involving flashing partitions or modifying system files, can potentially lead to device bricking or instability if not performed correctly. Also, while adb supports network connections, initial setup often requires a USB connection.
<B>ADB SERVER</B>
The adb server runs as a background process on your development machine (usually on port 5037). It listens for adb client commands, then manages communication with the adbd daemon on connected Android devices. It's automatically started when you run an adb command and can be explicitly controlled with adb start-server and adb kill-server.
<B>USB DEBUGGING</B>
For adb to communicate with an Android device via USB, 'USB debugging' must be enabled in the device's Developer options. This setting is typically hidden until you tap the 'Build number' seven times in the 'About phone' section of the device settings.
<B>WIRELESS ADB</B>
While primarily known for USB connections, adb can also connect to devices over Wi-Fi. This usually requires an initial USB connection to configure the device for TCP/IP communication (e.g., adb tcpip 5555), after which the USB cable can be disconnected, and subsequent connections are made using adb connect IP_ADDRESS:PORT.
HISTORY
adb has been an integral part of the Android SDK (Software Development Kit) since its early days, developed and maintained by Google. It was designed to provide developers with a robust tool to interact with Android devices for testing, debugging, and system access. Over the years, adb has seen continuous updates and improvements, adapting to new Android versions and device functionalities, ensuring compatibility and enhancing its capabilities for a wide range of debugging and development tasks. Its core functionality has remained consistent, making it a foundational tool in the Android ecosystem.
SEE ALSO
fastboot(1)