apache/cordova-android · error · CordovaError
Failed to find 'ANDROID_HOME' environment variable. Try sett
Error message
Failed to find 'ANDROID_HOME' environment variable. Try setting it manually. Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.
What it means
Terminal fallback of check_android: after all inference attempts (adb layout, avdmanager cmdline-tools layout), process.env.ANDROID_HOME is still empty. The message is generic because no tool gave a location to report - the SDK simply was not detectable.
Source
Thrown at lib/check_reqs.js:232
throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting it manually.\n' +
'Detected \'adb\' command at ' + parentDir + ' but no \'platform-tools\' directory found near.\n' +
'Try reinstall Android SDK or update your PATH to include valid path to SDK' + path.sep + 'platform-tools directory.');
}
}
if (avdmanagerInPath) {
let sdkPath = null;
if (/cmdline-tools/.test(avdmanagerInPath)) {
sdkPath = path.resolve(avdmanagerInPath, '../../../..');
maybeSetAndroidHome(sdkPath);
} else {
throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting it manually.\n' +
'Detected \'avdmanager\' command at ' + parentDir + ' but does not appear to be within an Android SDK installation.\n' +
'Try reinstall Android SDK or update your PATH to include valid path to SDK');
}
}
}
if (!process.env.ANDROID_HOME) {
throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting it manually.\n' +
'Failed to find \'android\' command in your \'PATH\'. Try update your \'PATH\' to include path to valid SDK directory.');
}
if (!fs.existsSync(process.env.ANDROID_HOME)) {
throw new CordovaError('\'ANDROID_HOME\' environment variable is set to non-existent path: ' + process.env.ANDROID_HOME +
'\nTry update it manually to point to valid SDK directory.');
}
// Next let's make sure relevant parts of the SDK tooling is in our PATH
if (hasAndroidHome && !adbInPath) {
process.env.PATH += path.delimiter + path.join(process.env.ANDROID_HOME, 'platform-tools');
}
if (hasAndroidHome && !avdmanagerInPath) {
const cmdLineToolsBin = AndroidCommandLineTools.getBinPath();
if (cmdLineToolsBin) {
process.env.PATH += path.delimiter + cmdLineToolsBin;
}
}
return hasAndroidHome;
});View on GitHub (pinned to 7c1e190064)
Solutions
- Install an Android SDK (Android Studio, or download command-line tools and run sdkmanager).
- Export ANDROID_HOME (and ANDROID_SDK_ROOT for older tooling) in ~/.profile or the CI environment.
- Verify with `cordova requirements android` - all checks should pass.
Example fix
# before: no SDK env anywhere $ cordova requirements android # after (~/.profile or CI env) export ANDROID_HOME="$HOME/Android/Sdk" export ANDROID_SDK_ROOT="$ANDROID_HOME" export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/latest/bin:$PATH"
Defensive patterns
Strategy: validation
Validate before calling
if (!process.env.ANDROID_HOME && !process.env.ANDROID_SDK_ROOT) {
throw new Error('ANDROID_HOME is unset and no SDK tools are on PATH - install the Android SDK and export ANDROID_HOME');
} Try / catch
try {
await check_reqs.run();
} catch (e) {
if (/Failed to find 'android' command/.test(e.message)) {
// no SDK at all: emit setup instructions and fail the job early
}
throw e;
} Prevention
- Provision the Android SDK as an explicit CI step (or use a managed image) before any cordova command.
- Centralize env exports in one profile/script sourced by shells and CI alike.
- Run `cordova requirements android` as a smoke test right after environment setup.
When it happens
Trigger: `cordova requirements android` / build / run on a machine where ANDROID_HOME and ANDROID_SDK_ROOT are unset and neither adb nor avdmanager is on PATH (or both inference branches above were skipped).
Common situations: Fresh machine or minimal CI container with no Android SDK installed; shell profile not sourcing the env exports; CI job missing the environment block.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- Failed to find 'ANDROID_HOME' environment variable. Try sett
- 'ANDROID_HOME' environment variable is set to non-existent p
- Failed to find 'ANDROID_HOME' environment variable. Try sett
- Requirements check failed for Android SDK! Android SDK was n
- Please install the Android SDK Platform "platforms;${desired
AI-assisted analysis of apache/cordova-android@7c1e190064 (2026-08-22).
Data as JSON: /api/errors/c286d727e5bb47e1.
Report an issue: GitHub.