{"record":{"id":"2ddeaf771f5e5d70","repo":"apache/cordova-android","slug":"failed-to-find-android-home-environment-variable","errorCode":null,"errorMessage":"Failed to find 'ANDROID_HOME' environment variable. Try setting it manually.\nDetected 'adb' command at ${parentDir} but no 'platform-tools' directory found near.\nTry reinstall Android SDK or update your PATH to include valid path to SDK${path.sep}platform-tools directory.","messagePattern":"Failed to find 'ANDROID_HOME' environment variable\\. Try setting it manually\\.\nDetected 'adb' command at (.+?) but no 'platform-tools' directory found near\\.\nTry reinstall Android SDK or update your PATH to include valid path to SDK(.+?)platform-tools directory\\.","errorType":"validation","errorClass":"CordovaError","httpStatus":null,"severity":"error","filePath":"lib/check_reqs.js","lineNumber":214,"sourceCode":"                maybeSetAndroidHome('/Applications/android-sdk');\n            }\n            if (process.env.HOME) {\n                // Stand-alone zip file that user might think to put under their home directory\n                maybeSetAndroidHome(path.join(process.env.HOME, 'android-sdk-macosx'));\n                maybeSetAndroidHome(path.join(process.env.HOME, 'android-sdk'));\n            }\n        }\n\n        if (!hasAndroidHome) {\n            // If we dont have ANDROID_HOME, but we do have some tools on the PATH, try to infer from the tooling PATH.\n            let parentDir, grandParentDir;\n            if (adbInPath) {\n                parentDir = path.dirname(adbInPath);\n                grandParentDir = path.dirname(parentDir);\n                if (path.basename(parentDir) === 'platform-tools') {\n                    maybeSetAndroidHome(grandParentDir);\n                } else {\n                    throw new CordovaError('Failed to find \\'ANDROID_HOME\\' environment variable. Try setting it manually.\\n' +\n                        'Detected \\'adb\\' command at ' + parentDir + ' but no \\'platform-tools\\' directory found near.\\n' +\n                        'Try reinstall Android SDK or update your PATH to include valid path to SDK' + path.sep + 'platform-tools directory.');\n                }\n            }\n            if (avdmanagerInPath) {\n                let sdkPath = null;\n                if (/cmdline-tools/.test(avdmanagerInPath)) {\n                    sdkPath = path.resolve(avdmanagerInPath, '../../../..');\n                    maybeSetAndroidHome(sdkPath);\n                } else {\n                    throw new CordovaError('Failed to find \\'ANDROID_HOME\\' environment variable. Try setting it manually.\\n' +\n                        'Detected \\'avdmanager\\' command at ' + parentDir + ' but does not appear to be within an Android SDK installation.\\n' +\n                        'Try reinstall Android SDK or update your PATH to include valid path to SDK');\n                }\n            }\n        }\n        if (!process.env.ANDROID_HOME) {\n            throw new CordovaError('Failed to find \\'ANDROID_HOME\\' environment variable. Try setting it manually.\\n' +","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/apache/cordova-android/blob/7c1e190064e349ffa4bbc6ac37b77cd773e4dbd3/lib/check_reqs.js#L196-L232","documentation":"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.","triggerScenarios":"`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.","commonSituations":"`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.","solutions":["Export ANDROID_HOME to your SDK root (e.g. export ANDROID_HOME=\"$HOME/Android/Sdk\") in your shell profile or CI env.","Install the full SDK via Android Studio or cmdline-tools so adb lives at $ANDROID_HOME/platform-tools/adb.","Point PATH at <sdk>/platform-tools instead of a shim directory."],"exampleFix":"# before\nexport PATH=\"$HOME/bin:$PATH\"   # adb copied into ~/bin\n\n# after\nexport ANDROID_HOME=\"$HOME/Android/Sdk\"\nexport PATH=\"$ANDROID_HOME/platform-tools:$PATH\"","handlingStrategy":"validation","validationCode":"function assertAndroidSdkEnv () {\n  const home = process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT;\n  if (!home) throw new Error('Set ANDROID_HOME to your SDK root');\n  if (!fs.existsSync(path.join(home, 'platform-tools', 'adb'))) {\n    throw new Error(`${home} has no platform-tools/adb - install the full SDK`);\n  }\n}\nassertAndroidSdkEnv(); // before cordova requirements/build","typeGuard":null,"tryCatchPattern":"try {\n  await check_reqs.check_android();\n} catch (e) {\n  if (/ANDROID_HOME/.test(e.message)) {\n    console.error('Fix the environment (see https://cordova.apache.org/docs/en/latest/guide/platforms/android/), then retry.');\n  }\n  throw e;\n}","preventionTips":["Export ANDROID_HOME (and ANDROID_SDK_ROOT) in ~/.profile and in the CI environment block.","Install SDKs via Android Studio / cmdline-tools so adb sits at <sdk>/platform-tools/adb; avoid standalone adb-only packages.","Verify setup with `cordova requirements android` before starting real work."],"tags":["android-sdk","android-home","environment-variable","path","adb"],"backgroundTag":"missing-env-var","analyzedSha":"7c1e190064e349ffa4bbc6ac37b77cd773e4dbd3","analyzedAt":"2026-08-22T04:57:58.868Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}