Appium "Could not find a connected Android device" in CI
Appium asked adb for the device list and got nothing back that is online, so the UiAutomator2 driver has nothing to install the app onto. The emulator either never booted, booted after Appium checked, or adb lost track of it.
What this error means
The Appium session request fails with "Could not find a connected Android device in 20000ms" or adb reports "no devices/emulators found". It is intermittent when the emulator boot races the test start.
[UiAutomator2] Error: Could not find a connected Android device in 20000ms.
> List of devices attached
> (empty)Common causes
The emulator has not finished booting yet
The test job starts Appium before sys.boot_completed is set, so adb still shows an offline or absent device when the driver polls.
adb lost the device or the server is not running
A headless CI emulator can drop off the adb bridge, or the adb server was not started, leaving "List of devices attached" empty.
How to fix it
Wait for boot before launching the session
- Start the emulator, then block until it reports boot completed.
- Only then start Appium and request the session.
- Give the wait a generous timeout for cold CI emulator starts.
adb wait-for-device
adb shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done'Use an emulator action that gates on readiness
The reactivecircus emulator action boots the AVD and waits before running your script, so Appium never races a cold device.
- uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 34
script: npx appium & sleep 5 && npm run e2eHow to prevent it
- Always gate the test start on
sys.boot_completed, not a fixed sleep. - Restart the adb server (
adb kill-server && adb start-server) if the device drops. - Give cold emulator boots a wide timeout on shared CI runners.