apache/cordova-android · error · CordovaError

No emulator ID given

Error message

No emulator ID given

What it means

emulator.start(emulatorId, boot_timeout) validates its first argument in the initial promise step and throws immediately when emulatorId is falsy. No default-AVD lookup or image resolution happens inside start() - the caller (the run/emulate flow) is expected to pick an existing AVD first.

Source

Thrown at lib/emulator.js:202

        }
        throw new CordovaError('Could not find an available avd port');
    });
};

/*
 * Starts an emulator with the given ID,
 * and returns the started ID of that emulator.
 * If no boot timeout is given or the value is negative it will wait forever for
 * the emulator to boot
 *
 * Returns a promise.
 */
module.exports.start = function (emulatorId, boot_timeout) {
    const self = this;

    return Promise.resolve().then(function () {
        if (!emulatorId) {
            throw new CordovaError('No emulator ID given');
        }

        return self.get_available_port().then(function (port) {
            // Figure out the directory the emulator binary runs in, and set the cwd to that directory.
            // Workaround for https://code.google.com/p/android/issues/detail?id=235461
            const emulator_dir = path.dirname(which.sync('emulator'));
            const args = ['-avd', emulatorId, '-port', port];
            // Don't wait for it to finish, since the emulator will probably keep running for a long time.
            execa('emulator', args, { stdio: 'inherit', detached: true, cwd: emulator_dir })
                .unref();

            // wait for emulator to start
            events.emit('log', 'Waiting for emulator to start...');
            return self.wait_for_emulator(port);
        });
    }).then(function (emulatorId) {
        if (!emulatorId) { return Promise.reject(new CordovaError('Failed to start emulator')); }

View on GitHub (pinned to 7c1e190064)

Solutions

  1. List available AVDs: `emulator -list-avds` or `avdmanager list avd`.
  2. Create one: `avdmanager create avd -n test -k "system-images;android-34;google_apis;x86_64"` (install the system image first via sdkmanager).
  3. Run again, optionally pinning it: `cordova emulate android --target=test`.

Example fix

# before
$ cordova emulate android   # no AVD on the machine
No emulator ID given

# after
$ sdkmanager "system-images;android-34;google_apis;x86_64"
$ avdmanager create avd -n test -k "system-images;android-34;google_apis;x86_64"
$ cordova emulate android --target=test
Defensive patterns

Strategy: validation

Validate before calling

if (!emulatorId) {
  throw new Error('No emulator ID given - list with `emulator -list-avds` and pass --target');
}
const avds = (await execa('emulator', ['-list-avds'])).stdout.split(/\r?\n/).filter(Boolean);
if (!avds.includes(emulatorId)) {
  throw new Error(`AVD '${emulatorId}' not found; available: ${avds.join(', ')}`);
}

Type guard

const isNonEmptyEmulatorId = (id) => typeof id === 'string' && id.trim().length > 0;

Prevention

When it happens

Trigger: Direct call emulator.start() / emulator.start(undefined), or `cordova emulate android` when the flow above it found no AVD image to pass (e.g. --target given as empty, or no AVDs exist on the machine).

Common situations: Fresh machine or CI image where no AVD has been created (`emulator -list-avds` empty); `cordova emulate android --target=` with an empty value; tooling assuming a default emulator exists.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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