| name | connecting-to-devices |
| description | Use this skill to attach a USB device or emulator to ADB, list transports with `adb devices` / `adb devices -l`, disambiguate among multiple devices using `-s SERIAL`, `-d` (single USB), `-e` (single TCP/IP), or `-t TRANSPORT_ID`, gate scripts on a transport with the canonical `adb wait-for[-TRANSPORT]-<state>` syntax (TRANSPORT in {usb, local, any}; state in {device, recovery, rescue, sideload, bootloader, disconnect}), interpret device states (`device`, `offline`, `unauthorized`, `no permissions`, `recovery`, `sideload`, `bootloader`, `rescue`), accept the RSA fingerprint dialog on first connect, and install Linux udev rules. Use when the user mentions `error: more than one device/emulator`, `error: device not found`, `unauthorized`, `no permissions`, `daemon not running`, "wait for device to boot", `wait-for-device-online` (which is not a real subcommand), or asks how to script around emulator startup. |
| license | Apache-2.0. See LICENSE for complete terms. |
| metadata | {"author":"Jaewoong Eum (skydoves)","keywords":["adb-devices","device-selector","transport-id","wait-for-device","unauthorized","no-permissions","udev-rules","usb-debugging","rsa-fingerprint","sys.boot_completed"]} |
Connecting to Devices — Listing, Selecting, and Waiting on Transports
adb devices is the most-typed adb command. The follow-on traps are real: scripts run before the device is actually online, multi-device shells fail with more than one device/emulator, Linux misses udev rules, and tutorials reference a fictional wait-for-device-online form. This skill encodes the truth set.
When to use this skill
- The user runs
adb shell with two devices plugged in and gets error: more than one device/emulator.
- The user reports a device showing as
unauthorized, offline, or no permissions in adb devices.
- The user wants a CI script to wait until a device finishes booting before running tests.
- The user copy-pasted
adb wait-for-device-online from a blog post and it errors with usage text.
- The user is on Linux and a freshly plugged phone never appears in
adb devices.
When NOT to use this skill
- The user wants the high-level architecture / server lifecycle / env vars — use
../../architecture/understanding-adb-architecture/SKILL.md.
- The user wants Wi-Fi / wireless debugging — use
../connecting-over-wifi/SKILL.md.
- The user wants to install or clear app state on the connected device — use
../../apps/installing-and-managing-apps/SKILL.md.
Prerequisites
- Working ADB server (see
../../architecture/understanding-adb-architecture/SKILL.md).
- Device with USB debugging enabled in
Settings → System → Developer options. On Android 4.2+ developer options is hidden until "Build number" is tapped seven times in About phone.
- On Linux: ability to write
/etc/udev/rules.d/51-android.rules with sudo.
- On Windows: a vendor USB driver (Google USB Driver via SDK Manager for Pixel/Nexus; OEM driver for other manufacturers).
Workflow
Patterns
Pattern: WRONG vs RIGHT — more than one device/emulator
adb shell getprop ro.product.model
adb -s emulator-5554 shell getprop ro.product.model
adb -d shell getprop ro.product.model
export ANDROID_SERIAL=emulator-5554
adb shell getprop ro.product.model
Pattern: WRONG vs RIGHT — fictional wait-for-device-online
adb wait-for-device-online
adb wait-for-device
until [[ "$(adb shell getprop sys.boot_completed | tr -d '\r')" == "1" ]]; do
sleep 1
done
Pattern: WRONG vs RIGHT — racing emulator startup
emulator -avd Pixel_API_34 &
adb install -r app.apk
adb start-server
emulator -avd Pixel_API_34 &
adb -s emulator-5554 wait-for-device
until [[ "$(adb -s emulator-5554 shell getprop sys.boot_completed | tr -d '\r')" == "1" ]]; do
sleep 1
done
adb -s emulator-5554 install -r app.apk
Corner case (verbatim from the adb page): "running emulators [may] not show up in adb devices ... when all of the following are true: the adb server is not running; you use the emulator command with the -port or -ports option with an odd-numbered port between 5554 and 5584; ... You start the adb server after you start the emulator." Workaround: adb start-server BEFORE emulator.
Pattern: WRONG vs RIGHT — transport_id vs -t confusion
adb -t 60 shell getprop ro.product.model
timeout 60 adb -s emulator-5554 shell getprop ro.product.model
gtimeout 60 adb -s emulator-5554 shell getprop ro.product.model
adb -t 2 shell getprop ro.product.model
Mandatory rules
- MUST add a selector (
-s/-d/-e/-t) on every adb command when more than one transport is attached, OR set $ANDROID_SERIAL.
- MUST use the documented
wait-for[-TRANSPORT]-<state> syntax. There is no wait-for-device-online.
- MUST poll
getprop sys.boot_completed after wait-for-device when the script needs the OS fully booted (e.g. before installing an APK or invoking am instrument).
- MUST NOT confuse
-t TRANSPORT_ID with a timeout flag. Wrap with timeout / gtimeout for actual timeouts.
- MUST NOT delete
~/.android/adbkey* to "fix" unauthorized — see ../../architecture/understanding-adb-architecture/SKILL.md for the correct recovery.
- PREFERRED: use
adb devices -l and transport_id for scripts that may see two devices with the same serial (rare hardware bug or duplicate AVDs).
- PREFERRED: install the distro's
android-udev package on Linux instead of hand-maintaining 51-android.rules.
Verification
References
- ADB user guide (
adb devices, wait-for-*, RSA dialog): https://developer.android.com/tools/adb
- Run-on-device setup (Linux udev rules and Windows drivers): https://developer.android.com/studio/run/device
- OEM USB drivers (Windows): https://developer.android.com/tools/extras/oem-usb
- AOSP
adb man page: https://android.googlesource.com/platform/packages/modules/adb/+/refs/heads/main/docs/user/adb.1.md
tasks/research/A1-adb-architecture-devices.md — verbatim wait-for-* table, the wait-for-device-online correction, full state set, udev rule recipe.
docs/CORPUS.md §I.3 (state truth set) and §I.10 (research findings).
- Sibling skills:
- High-level architecture:
../../architecture/understanding-adb-architecture/SKILL.md
- Wireless ADB:
../connecting-over-wifi/SKILL.md
- Install / clear apps:
../../apps/installing-and-managing-apps/SKILL.md
- Run instrumented tests:
../../tests/running-instrumented-tests-via-adb/SKILL.md
- Cross-set neighbours:
- Run instrumented tests with
AndroidJUnit4: ../../../instrumentation/runner/running-instrumented-tests-with-androidjunit4/SKILL.md
- Configure JUnit4 on Android:
../../../jvm-tests/runner/configuring-junit4-on-android/SKILL.md
- Source-set strategy:
../../../fundamentals/strategies/organizing-test-source-sets/SKILL.md