{"record":{"id":"73b768153d699155","repo":"FoundationAgents/MetaGPT","slug":"device-id-device-id-not-found","errorCode":null,"errorMessage":"device-id: {device_id} not found","messagePattern":"device-id: (.+?) not found","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"metagpt/environment/android/android_ext_env.py","lineNumber":63,"sourceCode":"\nclass AndroidExtEnv(ExtEnv):\n    device_id: Optional[str] = Field(default=None)\n    screenshot_dir: Optional[Path] = Field(default=None)\n    xml_dir: Optional[Path] = Field(default=None)\n    width: int = Field(default=720, description=\"device screen width\")\n    height: int = Field(default=1080, description=\"device screen height\")\n    ocr_detection: any = Field(default=None, description=\"ocr detection model\")\n    ocr_recognition: any = Field(default=None, description=\"ocr recognition model\")\n    groundingdino_model: any = Field(default=None, description=\"clip groundingdino model\")\n\n    def __init__(self, **data: Any):\n        super().__init__(**data)\n        device_id = data.get(\"device_id\")\n        self.ocr_detection, self.ocr_recognition, self.groundingdino_model = load_cv_model()\n        if device_id:\n            devices = self.list_devices()\n            if device_id not in devices:\n                raise RuntimeError(f\"device-id: {device_id} not found\")\n            (width, height) = self.device_shape\n            self.width = data.get(\"width\", width)\n            self.height = data.get(\"height\", height)\n            self.create_device_path(self.screenshot_dir)\n            self.create_device_path(self.xml_dir)\n\n    def reset(\n        self,\n        *,\n        seed: Optional[int] = None,\n        options: Optional[dict[str, Any]] = None,\n    ) -> tuple[dict[str, Any], dict[str, Any]]:\n        super().reset(seed=seed, options=options)\n\n        obs = self._get_obs()\n\n        return obs, {}\n","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/environment/android/android_ext_env.py#L45-L81","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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)."],"exampleFix":"# before\nenv = AndroidExtEnv(device_id=\"emulator-5556\")  # RuntimeError: device-id: emulator-5556 not found\n\n# after\nimport subprocess\nserials = [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]\nassert serials, \"no android devices connected; start the emulator first\"\nenv = AndroidExtEnv(device_id=serials[0])","handlingStrategy":"validation","validationCode":"import subprocess\n\ndef list_adb_serials() -> list[str]:\n    out = subprocess.run([\"adb\", \"devices\"], capture_output=True, text=True, check=True).stdout\n    return [l.split()[0] for l in out.splitlines()[1:] if l.strip() and l.split()[-1] == \"device\"]\n\nserials = list_adb_serials()\nassert serials, \"no authorized android devices; start emulator / accept USB debugging\"\nenv = AndroidExtEnv(device_id=serials[0])","typeGuard":null,"tryCatchPattern":"try:\n    env = AndroidExtEnv(device_id=serial)\nexcept RuntimeError as e:\n    if \"not found\" in str(e):\n        raise SystemExit(f\"device {serial!r} not connected; run `adb devices` and check the serial\") from e\n    raise","preventionTips":["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."],"tags":["python","android","adb","environment","device-connection"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}