{"record":{"id":"c1531db5c75a3292","repo":"apache/cordova-android","slug":"could-not-find-target-matching-inspect-spec","errorCode":null,"errorMessage":"Could not find target matching ${inspect(spec)}","messagePattern":"Could not find target matching (.+?)","errorType":"exception","errorClass":"CordovaError","httpStatus":null,"severity":"error","filePath":"lib/target.js","lineNumber":121,"sourceCode":"        'manifest', 'target-sdk', apkPath\n    ]);\n    return Number(targetSdkStr);\n}\n\n/**\n * @param {TargetSpec?} spec\n * @param {BuildResults} buildResults\n * @return {Promise<Target & {arch: string}>}\n */\nexports.resolve = async (spec, buildResults) => {\n    events.emit('verbose', `Trying to find target matching ${inspect(spec)}`);\n\n    const resolvedTarget =\n        (await resolveToOnlineTarget(spec)) ||\n        (await resolveToOfflineEmulator(spec, buildResults));\n\n    if (!resolvedTarget) {\n        throw new CordovaError(`Could not find target matching ${inspect(spec)}`);\n    }\n\n    return {\n        ...resolvedTarget,\n        arch: await build.detectArchitecture(resolvedTarget.id)\n    };\n};\n\nexports.install = async function ({ id: target, arch, type }, { manifest, buildResults, cordovaGradleConfigParser }) {\n    const apk_path = build.findBestApkForArchitecture(buildResults, arch);\n    const pkgName = cordovaGradleConfigParser.getPackageName();\n    const launchName = pkgName + '/.' + manifest.getActivity().getName();\n\n    events.emit('log', 'Using apk: ' + apk_path);\n    events.emit('log', 'Package name: ' + pkgName);\n    events.emit('verbose', `Installing app on target ${target}`);\n\n    async function doInstall (execOptions = {}) {","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/apache/cordova-android/blob/7c1e190064e349ffa4bbc6ac37b77cd773e4dbd3/lib/target.js#L103-L139","documentation":"target.resolve tries two strategies in order: an already-online target (adb-visible device or booted emulator) matching the spec, then starting an offline emulator from a matching AVD. If both fail — nothing connected and no startable emulator that satisfies the requested id/type — it throws this CordovaError with the inspected spec.","triggerScenarios":"`cordova run android` with no device/emulator attached; with --target=<id> where id matches neither an adb device (adb devices) nor an AVD name (avdmanager list avd); with --emulator when no AVD images are installed; or --device with only an emulator online (resolveToOfflineEmulator returns null for type 'device').","commonSituations":"USB debugging not authorized (device shows as unauthorized in adb), cable/adb server issues, emulator deleted or never created, wrong serial passed to --target, CI runner without KVM and without any attached device.","solutions":["Attach/authorize a device: enable Developer Options + USB debugging, plug in, accept the RSA prompt, confirm with `adb devices` (state must be 'device', not 'unauthorized'), then re-run","Or start an emulator: `avdmanager list avd` to see images, create/boot one (`emulator -avd <name>`), or rely on cordova to auto-start by omitting --target","If you pass --target, use an exact adb serial (e.g. emulator-5554, device serial) or exact AVD name; remove a stale --target to let cordova pick any available target","On headless CI install system images and an AVD, or connect a cloud/device-farm device via adb"],"exampleFix":"# before\ncordova run android --target=ZX1D63        # serial not connected -> throws\n\n# after\nadb devices                                 # verify the serial is listed & authorized\ncordova run android --target=ZX1D63\n# or simply:\ncordova run android                          # picks device, else auto-starts emulator","handlingStrategy":"validation","validationCode":"// pre-flight for CI: require at least one authorized adb target or a startable AVD\nconst { execSync } = require('child_process');\nconst devices = execSync('adb devices').toString()\n  .split('\\n').slice(1).filter(l => l.trim() && l.endsWith('device'));\nif (devices.length === 0 && execSync('emulator -list-avds').toString().trim() === '') {\n  throw new Error('No device or emulator available for cordova run');\n}","typeGuard":null,"tryCatchPattern":"try { await cordova.run('android'); } catch (e) {\n  if (/Could not find target matching/.test(e.message)) { /* check adb devices authorization / start an AVD / drop --target */ }\n}","preventionTips":["Accept the USB debugging RSA prompt and confirm `adb devices` shows state 'device'","Create at least one AVD per dev machine and CI runner","Pass exact adb serials or AVD names to --target","Retry after emulator boot instead of racing it"],"tags":["cordova","cordova-android","run","device","emulator","adb"],"backgroundTag":"no-device-found","analyzedSha":"7c1e190064e349ffa4bbc6ac37b77cd773e4dbd3","analyzedAt":"2026-08-22T04:57:58.868Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}