apache/cordova-android · error · CordovaError

'ANDROID_HOME' environment variable is set to non-existent p

Error message

'ANDROID_HOME' environment variable is set to non-existent path: ${process.env.ANDROID_HOME}
Try update it manually to point to valid SDK directory.

What it means

check_android accepts a set or inferred ANDROID_HOME, then verifies the directory actually exists with fs.existsSync. Thrown when the variable points nowhere - the value survives env expansion but the directory itself is missing.

Source

Thrown at lib/check_reqs.js:236

            }
            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;
    });
};

module.exports.check_android_target = function (projectRoot) {
    // valid_target can look like:

View on GitHub (pinned to 7c1e190064)

Solutions

  1. Find the real SDK path (Android Studio > Settings > Languages & Frameworks > Android SDK, or the parent of your working adb's directory).
  2. Export the corrected ANDROID_HOME, making sure to use $HOME instead of a quoted ~.
  3. If the SDK really is gone, reinstall it (Android Studio or cmdline-tools + sdkmanager).

Example fix

# before
export ANDROID_HOME="~/Android/Sdk"   # '~' is literal inside double quotes

# after
export ANDROID_HOME="$HOME/Android/Sdk"
Defensive patterns

Strategy: validation

Validate before calling

const home = process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT;
if (home && !fs.existsSync(home)) {
  throw new Error(`ANDROID_HOME=${home} does not exist - fix the path (use $HOME, not a quoted ~)`);
}

Try / catch

try {
  await check_reqs.check_android();
} catch (e) {
  if (/set to non-existent path/.test(e.message)) {
    // print the offending value and the detected SDK location from Android Studio/adb
  }
  throw e;
}

Prevention

When it happens

Trigger: `cordova requirements android` / build with ANDROID_HOME containing a typo, a stale path (SDK moved or uninstalled), an unexpanded '~' inside quotes, or a wrong CI secret value.

Common situations: SDK directory renamed after a major version change; macOS/Linux '~' not expanded because the assignment used quotes; CI secret defined once and never updated after the SDK image changed.

Related errors


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