FoundationAgents/MetaGPT · error · RuntimeError
device-id: {device_id} not found
Error message
device-id: {device_id} not found What it means
AndroidExtEnv.__init__ runs `adb devices`, and if the user-supplied device_id is not among the connected devices it raises RuntimeError 'device-id: {device_id} not found'. This happens during model loading, before any path setup, and guards against sending subsequent adb commands to a nonexistent device.
Source
Thrown at metagpt/environment/android/android_ext_env.py:63
class AndroidExtEnv(ExtEnv):
device_id: Optional[str] = Field(default=None)
screenshot_dir: Optional[Path] = Field(default=None)
xml_dir: Optional[Path] = Field(default=None)
width: int = Field(default=720, description="device screen width")
height: int = Field(default=1080, description="device screen height")
ocr_detection: any = Field(default=None, description="ocr detection model")
ocr_recognition: any = Field(default=None, description="ocr recognition model")
groundingdino_model: any = Field(default=None, description="clip groundingdino model")
def __init__(self, **data: Any):
super().__init__(**data)
device_id = data.get("device_id")
self.ocr_detection, self.ocr_recognition, self.groundingdino_model = load_cv_model()
if device_id:
devices = self.list_devices()
if device_id not in devices:
raise RuntimeError(f"device-id: {device_id} not found")
(width, height) = self.device_shape
self.width = data.get("width", width)
self.height = data.get("height", height)
self.create_device_path(self.screenshot_dir)
self.create_device_path(self.xml_dir)
def reset(
self,
*,
seed: Optional[int] = None,
options: Optional[dict[str, Any]] = None,
) -> tuple[dict[str, Any], dict[str, Any]]:
super().reset(seed=seed, options=options)
obs = self._get_obs()
return obs, {}
View on GitHub (pinned to 11cdf466d0)
Solutions
- Verify the exact serial with `adb devices` and pass that value as device_id.
- Ensure the emulator/device is fully booted and authorized (accept the USB debugging prompt) before constructing AndroidExtEnv.
- Confirm adb is installed and on PATH; on Windows use the full path to adb.exe.
- If multiple devices are attached, qualify all adb commands with -s <device_id> (the class does this internally via adb_prefix_shell once the id validates).
Example fix
# before env = AndroidExtEnv(device_id="emulator-5556") # RuntimeError: device-id: emulator-5556 not found # after import subprocess serials = [l.split()[0] for l in subprocess.run(["adb", "devices"], capture_output=True, text=True).stdout.splitlines()[1:] if l.strip() and "device" in l] assert serials, "no android devices connected; start the emulator first" env = AndroidExtEnv(device_id=serials[0])
Defensive patterns
Strategy: validation
Validate before calling
import subprocess
def list_adb_serials() -> list[str]:
out = subprocess.run(["adb", "devices"], capture_output=True, text=True, check=True).stdout
return [l.split()[0] for l in out.splitlines()[1:] if l.strip() and l.split()[-1] == "device"]
serials = list_adb_serials()
assert serials, "no authorized android devices; start emulator / accept USB debugging"
env = AndroidExtEnv(device_id=serials[0]) Try / catch
try:
env = AndroidExtEnv(device_id=serial)
except RuntimeError as e:
if "not found" in str(e):
raise SystemExit(f"device {serial!r} not connected; run `adb devices` and check the serial") from e
raise Prevention
- Run `adb devices` yourself and pass a serial from its output; never hardcode a serial without verifying.
- Wait for the emulator to finish booting before constructing AndroidExtEnv (poll `adb shell getprop sys.boot_completed`).
- Accept the USB-debugging authorization prompt on physical devices; unauthorized devices are excluded.
When it happens
Trigger: Constructing AndroidExtEnv(device_id="emulator-5554") when `adb devices` lists nothing or a different serial (e.g. the emulator is not started, or the physical phone is unauthorized).
Common situations: Emulator not booted yet (race between starting the emulator and running the script); USB debugging not authorized so the device shows as 'unauthorized' and its serial is excluded; multiple devices attached and the wrong serial copied; adb not on PATH making list_devices return an empty list.
Related errors
- create device path: {folder_path} failed
- api_name: {api_name} not found
- {rw_api} not exists
- Environment has not been reset yet
- Failed to step Minecraft server
AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14).
Data as JSON: /api/errors/73b768153d699155.
Report an issue: GitHub.