Skip to content

What is ADB? ​

ADB, the Android Debug Bridge, is how a computer gives instructions to an Android phone over a cable or a network. By the end of this lesson you will know its three parts, how a phone decides to trust a computer, and how to read the list adb devices prints.

One tool, three programs ​

When you type an adb command, three programs take part:

text
 YOUR COMPUTER                                     THE PHONE
┌──────────────────────────────────────┐          ┌──────────────────┐
│                                      │   USB    │                  │
│  adb devices ──► adb server ─────────┼──────────┼──► adbd          │
│  (the client)    (background,        │  or      │    (the daemon)  │
│                   port 5037)         │  Wi-Fi   │                  │
│  DroidDeck ────►     ▲               │          │  runs the        │
│  (another client)    │               │          │  command, sends  │
│                      │               │          │  the answer back │
└──────────────────────┼───────────────┘          └──────────────────┘
                       │
             one server, many clients
ProgramWhere it runsWhat it does
ClientYour computerThe adb command you type. It sends your request to the server and prints the answer.
ServerYour computer, in the backgroundKeeps track of every connected device and passes requests to the right one. It listens on port 5037 of your own computer.
Daemon (adbd)The phoneReceives requests and carries them out: installs, copies, runs commands. A daemon is a program that runs in the background waiting for work.

The server starts by itself the first time you run an adb command, and keeps running after you close the terminal. You see this the first time:

text
$ adb devices
* daemon not running; starting now at tcp:5037
* daemon started successfully
List of devices attached

Here "daemon" means the adb server on your computer, which is a little confusing: the phone's program is also a daemon. To stop the server, run adb kill-server. It starts again the next time any client needs it.

DroidDeck is another client. It runs the same adb commands you would type, through the same server, and shows the results in a window. Anything DroidDeck does, adb can do from a terminal.

Get adb on your computer ​

adb is part of Google's Android SDK Platform-Tools, a small download that also contains fastboot. Three common ways to get it:

  • Download Platform-Tools for your system from the Android developers site, unpack it, and run adb from that folder or add the folder to your PATH.
  • Install your Linux distribution's package: sudo apt install adb on Debian and Ubuntu, sudo dnf install android-tools on Fedora.
  • Install Android Studio, which keeps a copy in ~/Android/Sdk/platform-tools.

The DroidDeck snap carries its own adb. See Install DroidDeck for every package.

Check it works:

bash
adb version

It prints Android Debug Bridge version, the version numbers, and where the program is installed.

Developer options and USB debugging ​

A phone ignores ADB until you switch it on. The switch is in a menu that Android hides from everyday users, Developer options.

  1. Open Settings, then About phone, and tap Build number seven times. The phone may ask for your PIN, then says you are now a developer.

    The place varies by maker. On some phones Build number is under Software information.

  2. Open Developer options. It is usually under Settings › System.

  3. Turn on USB debugging and confirm.

An Android emulator, such as the one in Android Studio, has debugging on already and needs none of this.

The authorisation prompt ​

Turning on USB debugging is not enough. The phone also has to trust this computer.

The first time you run adb on a computer, it creates a key pair in your home folder: a private key, ~/.android/adbkey, and a public key, ~/.android/adbkey.pub. When you plug in a phone, the server shows the phone its public key, and the phone asks you:

text
┌────────────────────────────────────────────┐
│  Allow USB debugging?                      │
│                                            │
│  The computer's RSA key fingerprint is:    │
│  4F:2A:…:9C                                │
│                                            │
│  ☐ Always allow from this computer         │
│                                            │
│              Cancel        Allow           │
└────────────────────────────────────────────┘

The fingerprint is a short summary of the computer's public key, a different one for every computer. Tick Always allow from this computer and the phone remembers the key, so it does not ask again. Leave it unticked and it asks every time you connect.

Until you select Allow, the computer can see that a phone is there, but can do nothing with it. That is the point: a stranger who plugs your locked phone into their laptop gets no access, because the prompt only shows on an unlocked screen.

WARNING

Treat the prompt like a door key. Only allow a computer you own or fully trust. Never accept it on a shared computer, a public charging kiosk or a stranger's laptop. And keep ~/.android/adbkey private: anyone with a copy can act as your computer to every phone that has allowed it.

Device states ​

adb devices lists every device the server can see, with a serial number that identifies it and its state:

text
$ adb devices
List of devices attached
emulator-5554   device
R58N12ABCDE     unauthorized

Add -l for more detail, including the model:

text
$ adb devices -l
List of devices attached
emulator-5554   device product:sdk_gphone64_x86_64 model:sdk_gphone64_x86_64 device:emu64x transport_id:1
R58N12ABCDE     unauthorized usb:1-2 transport_id:2

The states you will meet:

StateWhat it meansWhat to do
deviceConnected, authorised and ready.Nothing.
unauthorizedThe phone has not allowed this computer yet.Unlock the phone and select Allow.
offlineThe server can see the device, but it is not answering.Unplug and replug. If that fails, adb kill-server and try again.
no permissionsOn Linux, your user may not open this USB device.Install your distribution's adb package, which brings the udev rules, and replug.

DroidDeck shows the same states on its Devices tab, with one difference in wording: the ready state device is shown as online. See Connect a device.

Talk to one device among several ​

With more than one device connected, adb refuses to guess:

text
$ adb shell
adb: more than one device/emulator

Name the one you mean with -s and its serial:

bash
adb -s emulator-5554 shell

-d picks the only USB device and -e the only emulator. DroidDeck does the same thing with its device picker: every tab acts on the device shown there, and it adds -s with that serial to each command.

Stay safe ​

  • Only debug devices you own or have permission to test. ADB can read files, install apps and run commands; using it on someone else's phone without asking is an intrusion.
  • Only allow computers you trust. If you ever accepted the prompt somewhere you should not have, open Developer options and select Revoke USB debugging authorizations. Every computer then has to ask again.
  • Watch for the prompt appearing when you did not expect it. It means some computer is trying to connect. Select Cancel.
  • Turn USB debugging off when you are done for the day, or turn Developer options off altogether with the switch at the top of that menu.

Check yourself ​

QuizWhat is ADB?

Question 1 of 6

Which part of ADB runs on the phone and carries out the requests?

Score: 0

What you learned ​

  • ADB has a client (the adb command or an app like DroidDeck), a server on your computer, and a daemon, adbd, on the device.
  • USB debugging in Developer options lets the daemon listen; the authorisation prompt decides which computers it obeys.
  • adb devices shows each device's serial and state. Only device (DroidDeck: online) is ready to use.
  • With several devices, pick one with -s and its serial.

Next steps ​