Android Debug Bridge - ArchWiki

Jump to content

# Android Debug Bridge

From ArchWiki

The Android Debug Bridge—adb(1)—is a command-line tool, that can be used to install, uninstall and debug applications, transfer files and access a device shell.

## Installation

adb is a part of the android-tools package and the Platform-Tools SDK package.

## Usage

### Connect a device

Tip

- systemd includes basic udev rules for Android devices to make adb and fastboot work out of the box. If your device does not show up, try to install the android-udev package with additional rules.
- Many devices' udev rules are included in libmtp, so if you have this installed, the following steps may not be necessary.
- For some devices, you may have to enable MTP on the device, before adb will work.
- Some other devices require enable PTP mode to work.
- Make sure your USB cable is capable of both charge and data. USB cables bundled with mobile devices might not include the USB data pin.

Note Devices running Android 10 or older do not support Wireless Debugging.

First you must enable Developer Mode on your device. To do so you must:

1. Go to Settings > About Phone, tap Build Number seven times until you get a popup that you have become a developer. Build number may be under a menu called Software info on newer Android OS versions.
2. Go to Developer Options and make sure it is on.

To connect to a real device via adb with USB, you must:

- Plug in your Android device via USB.
- Go to Settings > Developer > USB debugging and enable it. The device will ask to allow the computer with its fingerprint to connect.
- Checking allowing it permanently option will copy `~/.android/adbkey.pub` to the target phone `/data/misc/adb/adb_keys` location.

To connect a real device via adb with Wifi, you must:

- Make sure your device is on the same Wifi network as your computer.
- Go to Settings > Developer > Wireless debugging and enable it.
- Tap Pair device with pairing code.
- Run `adb pair <IP>:<Port> <Pair code>`.
- Run `adb connect <IP>:<Port>`. The port will be different than the one provided to pair.
- You should see your computer listed under Paired Devices.

If adb recognizes your device—`adb devices` shows it as `device` and not as `unauthorized`—you are done. Otherwise see the instructions below.

### Figure out device IDs

Each Android device has a USB vendor/product ID. An example for HTC Evo is:

    vendor id: 0bb4
    product id: 0c8d

Plug in your device and execute:

    $ lsusb

    …
    Bus 002 Device 006: ID 0bb4:0c8d High Tech Computer Corp.
    …

### Add udev rules

If your device is not included in android-udev, use the following template to create a custom udev rule by replacing `VENDOR_ID` and `PRODUCT_ID` with the IDs of your device:

    /etc/udev/rules.d/51-android.rules

    ACTION!="remove", SUBSYSTEM=="usb", ATTR{idVendor}=="VENDOR_ID", MODE="0660", GROUP="adbusers", ENV{ID_DEBUG_APPLIANCE}="android"
    ACTION!="remove", SUBSYSTEM=="usb", ATTR{idVendor}=="VENDOR_ID", ATTR{idProduct}=="PRODUCT_ID", SYMLINK+="android_adb"
    ACTION!="remove", SUBSYSTEM=="usb", ATTR{idVendor}=="VENDOR_ID", ATTR{idProduct}=="PRODUCT_ID", SYMLINK+="android_fastboot"

then reload the udev rules.

### Detect the device

After you have setup the udev rules, unplug your device and replug it.

After running:

    $ adb devices

    List of devices attached
    HT07VHL00676    device

If adb still does not detect the device after plugging your device back in, kill and restart the adb server as root user and check devices again:

    # adb kill-server
    # adb start-server
    $ adb devices

- If `adb devices` still shows `unauthorized` next to your device, make sure that that device has debugging permission allowed on the device itself.
  - An Allow USB Debugging? dialog should be presented when you physically connect the device. Select Always Allow…, then tap OK.
  - If the dialog was never presented, try Settings > Developer Options > Revoke USB Debugging Authorizations, then tap OK, and repeat the steps in this section.
- If you still do not see the Allow USB Debugging? dialog, and the device is listed as unauthorized, then enter the Developer Options on the device and first uncheck USB Debugging and then check it again.

### Transferring files

You can now use adb to transfer files between the device and your computer. To transfer files to the device, use:

    $ adb push what_to_copy where_to_place

To transfer files from the device, use:

    $ adb pull what_to_pull where_to_place

Also see #Tools building on adb.

### Backup and restore

Note `adb backup` and `adb restore` are deprecated and may be removed in a future release.

You can also backup and restore your device with adb. Moreover, no root user is required to follow the process. The commands below led to backup your device to a single file which can also be successively restored.

The command to create a backup is:

    $ adb backup -apk -shared -all -f backupFileName.ab

The command parameters list is:

    adb backup [-f <file>] [-apk|-noapk] [-shared|-noshared] [-all] [-system|nosystem] [<packages...>]

Then confirm the process on your device's display and provide a password whether a backup password has been set before.

The command to restore a previous backup is:

    $ adb restore backupFileName.ab

Note Remember that restoring operation will replace your device contents with the backup contents.

## Tools building on adb

- adb-sync-git — A tool to synchronize files between a PC and an Android device using the Android Debug Bridge protocol.

  https://github.com/google/adb-sync || adb-sync-gitAUR

- adbfs-rootless-git — Mount an Android device connected via USB.

  https://github.com/spion/adbfs-rootless || adbfs-rootless-gitAUR

- adbmanager-bin — The program is designed for visual and easy management of the adb server and connection of Android smartphones. Allows you to monitor the status of the adb service, manage it, and control the list of connected devices. Allows you to manage your smartphone: search for installed packages by part name, install, delete APK, screenshot, reboot (Normal, Bootloader, Recovery mode) and shutdown the device. For advanced users, there is an Android Shell terminal and an SD-Card file manager.

  https://github.com/AKotov-dev/adbmanager || adbmanager-binAUR

- androidscreencast-bin — View and control your Android device via adb from a PC.

  https://github.com/xSAVIKx/AndroidScreencast || androidscreencast-binAUR

- logcat-color3 — A colorful and highly configurable alternative to the standard `adb logcat` command.

  https://github.com/yan12125/logcat-color3 || logcat-color3AUR

- qtscrcpy — Android real-time display control software.

  https://github.com/barry-ran/QtScrcpy || qtscrcpyAUR

- scrcpy — Display and control your Android device.

  https://github.com/Genymobile/scrcpy || scrcpy

## Troubleshooting

### Empty device list

Possible causes for your device to not show up:

- Not having enabled USB debugging on your device. See #Connect a device.
- Using a power only—charge-only—USB cable and not an USB data transfer cable.

### No permissions error

If the device shows up with a `no permissions` label, it probably has a different vendor/product ID with respect to the ones collected by android-udev.

This can happen for instance when the device uses a custom ROM, or when it is switched from MTP to USB tethering mode, sideload and/or fastboot mode. Verify the actual device's ID with lsusb and #Add udev rules.

### Daemon exits with insufficient permissions error

If you see following error when running adb:

    E adb     : usb_libusb.cpp:571 failed to open device: Access denied (insufficient permissions)

check if you are in `adbusers` group.

### mdns

mdns is not supported by android-tools—you will see the following errors when running `adb mdns services` or `adb mdns check`:

    unknown host service 'mdns:check'
    unknown host service 'mdns:services'

To use mdns switch to the android-sdk-platform-toolsAUR SDK package.

If you encounter `error: unknown host service` — add the environment variable `ADB_MDNS_OPENSCREEN=1`. To connect automatically with a script, consider this gist.

Category:

- Android

Android Debug Bridge
Add topic