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.
Detected 'adb' command at ${parentDir} but no 'platform-tools' directory found near.
Try reinstall Android SDK or update your PATH to include valid path to SDK${path.sep}platform-tools directory.

What it means

Part of check_android's SDK detection: ANDROID_HOME/ANDROID_SDK_ROOT are unset (hasAndroidHome false) but adb was located on PATH. The SDK root is inferred only when adb's parent directory is literally named 'platform-tools' (<sdk>/platform-tools/adb -> sdk = grandparent). This error reports the adb directory when that layout check fails.

Source

Thrown at lib/check_reqs.js:214

                maybeSetAndroidHome('/Applications/android-sdk');
            }
            if (process.env.HOME) {
                // Stand-alone zip file that user might think to put under their home directory
                maybeSetAndroidHome(path.join(process.env.HOME, 'android-sdk-macosx'));
                maybeSetAndroidHome(path.join(process.env.HOME, 'android-sdk'));
            }
        }

        if (!hasAndroidHome) {
            // If we dont have ANDROID_HOME, but we do have some tools on the PATH, try to infer from the tooling PATH.
            let parentDir, grandParentDir;
            if (adbInPath) {
                parentDir = path.dirname(adbInPath);
                grandParentDir = path.dirname(parentDir);
                if (path.basename(parentDir) === 'platform-tools') {
                    maybeSetAndroidHome(grandParentDir);
                } else {
                    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' +

View on GitHub (pinned to 7c1e190064)

Solutions

  1. Export ANDROID_HOME to your SDK root (e.g. export ANDROID_HOME="$HOME/Android/Sdk") in your shell profile or CI env.
  2. Install the full SDK via Android Studio or cmdline-tools so adb lives at $ANDROID_HOME/platform-tools/adb.
  3. Point PATH at <sdk>/platform-tools instead of a shim directory.

Example fix

# before
export PATH="$HOME/bin:$PATH"   # adb copied into ~/bin

# after
export ANDROID_HOME="$HOME/Android/Sdk"
export PATH="$ANDROID_HOME/platform-tools:$PATH"
Defensive patterns

Strategy: validation

Validate before calling

function assertAndroidSdkEnv () {
  const home = process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT;
  if (!home) throw new Error('Set ANDROID_HOME to your SDK root');
  if (!fs.existsSync(path.join(home, 'platform-tools', 'adb'))) {
    throw new Error(`${home} has no platform-tools/adb - install the full SDK`);
  }
}
assertAndroidSdkEnv(); // before cordova requirements/build

Try / catch

try {
  await check_reqs.check_android();
} catch (e) {
  if (/ANDROID_HOME/.test(e.message)) {
    console.error('Fix the environment (see https://cordova.apache.org/docs/en/latest/guide/platforms/android/), then retry.');
  }
  throw e;
}

Prevention

When it happens

Trigger: `cordova requirements android` / build / run with adb on PATH from a non-standard location - Homebrew shims (/opt/homebrew/bin/adb), a manually copied adb binary, or a renamed platform-tools directory - and no ANDROID_HOME set.

Common situations: `brew install android-platform-tools` without installing the full SDK; user copied adb into ~/bin; SDK directory moved after PATH was configured; CI image that only ships adb.

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


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