apache/cordova-android · error · CordovaError

Could not find target matching ${inspect(spec)}

Error message

Could not find target matching ${inspect(spec)}

What it means

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.

Source

Thrown at lib/target.js:121

        'manifest', 'target-sdk', apkPath
    ]);
    return Number(targetSdkStr);
}

/**
 * @param {TargetSpec?} spec
 * @param {BuildResults} buildResults
 * @return {Promise<Target & {arch: string}>}
 */
exports.resolve = async (spec, buildResults) => {
    events.emit('verbose', `Trying to find target matching ${inspect(spec)}`);

    const resolvedTarget =
        (await resolveToOnlineTarget(spec)) ||
        (await resolveToOfflineEmulator(spec, buildResults));

    if (!resolvedTarget) {
        throw new CordovaError(`Could not find target matching ${inspect(spec)}`);
    }

    return {
        ...resolvedTarget,
        arch: await build.detectArchitecture(resolvedTarget.id)
    };
};

exports.install = async function ({ id: target, arch, type }, { manifest, buildResults, cordovaGradleConfigParser }) {
    const apk_path = build.findBestApkForArchitecture(buildResults, arch);
    const pkgName = cordovaGradleConfigParser.getPackageName();
    const launchName = pkgName + '/.' + manifest.getActivity().getName();

    events.emit('log', 'Using apk: ' + apk_path);
    events.emit('log', 'Package name: ' + pkgName);
    events.emit('verbose', `Installing app on target ${target}`);

    async function doInstall (execOptions = {}) {

View on GitHub (pinned to 7c1e190064)

Solutions

  1. 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
  2. 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
  3. 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
  4. On headless CI install system images and an AVD, or connect a cloud/device-farm device via adb

Example fix

# before
cordova run android --target=ZX1D63        # serial not connected -> throws

# after
adb devices                                 # verify the serial is listed & authorized
cordova run android --target=ZX1D63
# or simply:
cordova run android                          # picks device, else auto-starts emulator
Defensive patterns

Strategy: validation

Validate before calling

// pre-flight for CI: require at least one authorized adb target or a startable AVD
const { execSync } = require('child_process');
const devices = execSync('adb devices').toString()
  .split('\n').slice(1).filter(l => l.trim() && l.endsWith('device'));
if (devices.length === 0 && execSync('emulator -list-avds').toString().trim() === '') {
  throw new Error('No device or emulator available for cordova run');
}

Try / catch

try { await cordova.run('android'); } catch (e) {
  if (/Could not find target matching/.test(e.message)) { /* check adb devices authorization / start an AVD / drop --target */ }
}

Prevention

When it happens

Trigger: `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').

Common situations: 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.

Related errors


AI-assisted analysis of apache/cordova-android@7c1e190064 (2026-08-22). Data as JSON: /api/errors/c1531db5c75a3292. Report an issue: GitHub.