Skip to content

fix(android): workaround multi-device scrcpy initialization failure#2663

Open
jackliuw1983-afk wants to merge 1 commit into
web-infra-dev:mainfrom
jackliuw1983-afk:fix/scrcpy-multi-device-support
Open

fix(android): workaround multi-device scrcpy initialization failure#2663
jackliuw1983-afk wants to merge 1 commit into
web-infra-dev:mainfrom
jackliuw1983-afk:fix/scrcpy-multi-device-support

Conversation

@jackliuw1983-afk

Copy link
Copy Markdown

Summary

Fix --useScrcpy failing with "more than one device/emulator" when multiple Android devices are connected to the host machine.

Problem

When 2+ devices are connected, scrcpy initialization fails:

[Midscene] Scrcpy unavailable, using ADB fallback (device: e986b63e): 
Failed to initialize Scrcpy for device e986b63e. 
Error: Error: more than one device/emulator

Root Cause

The upstream @yume-chan/adb library's getDeviceFeatures() uses a two-step ADB protocol:

  1. host:transport-id:N → OKAY (transport switch)
  2. host:features → FAIL ❌ (ADB server doesn't inherit device context for host services)

The correct one-shot format (host-serial:S:features) works in all environments.

Fix

Add a runtime workaround in ScrcpyDeviceAdapter.ensureManager() that catches the specific "more than one device/emulator" error and retries using the one-shot protocol format. This is a non-invasive try/catch wrapper around the original method — single-device environments are completely unaffected (the original path succeeds without triggering the fallback).

Testing

Verified on Ubuntu 22.04 with 2 USB-connected Android devices:

# Before fix:
midscene-android connect --device-id e986b63e --useScrcpy
# → Scrcpy unavailable, using ADB fallback ❌

# After fix:
midscene-android connect --device-id e986b63e --useScrcpy
# → [midscene] Using scrcpy for screenshots (device: e986b63e) ✅

midscene-android connect --device-id fe40de17 --useScrcpy
# → [midscene] Using scrcpy for screenshots (device: fe40de17) ✅

Upstream

The root cause fix has been submitted to @yume-chan/ya-webadb:
yume-chan/ya-webadb#849

This workaround can be removed once the upstream fix is released and the dependency is updated.

Related

Closes #2662

When multiple Android devices are connected, scrcpy initialization fails
with "more than one device/emulator" due to a bug in @yume-chan/adb's
getDeviceFeatures() which uses a two-step ADB protocol that doesn't
inherit device context for host-level services.

This adds a runtime workaround that catches the specific error and falls
back to the one-shot protocol format (host-serial:S:features) which
works correctly in all environments.

Upstream fix: yume-chan/ya-webadb#849
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] --useScrcpy fails with 'more than one device/emulator' in multi-device environments

1 participant