{"record":{"id":"4f5dd7e4fabe408c","repo":"dotnet/maui","slug":"environment-variable-android-sdk-root-or-androi","errorCode":null,"errorMessage":"Environment variable 'ANDROID_SDK_ROOT' or 'ANDROID_HOME' must be set to the Android SDK root.","messagePattern":"Environment variable 'ANDROID_SDK_ROOT' or 'ANDROID_HOME' must be set to the Android SDK root\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"eng/cake/helpers.cake","lineNumber":79,"sourceCode":"    !String.IsNullOrWhiteSpace(GetAgentName());\n\nbool IsHostedAgent() =>\n    GetAgentName().StartsWith(\"Azure Pipelines\") || GetAgentName().StartsWith(\"Hosted Agent\");\n\nT GetBuildVariable<T>(string key, T defaultValue)\n{\n    // on MAC all environment variables are upper case regardless of how you specify them in devops\n    // And then Environment Variable check is case sensitive\n    T upperCaseReturnValue = Argument(key.ToUpper(), EnvironmentVariable(key.ToUpper(), defaultValue));\n    return Argument(key, EnvironmentVariable(key, upperCaseReturnValue));\n}\n\nstring GetAndroidSDKPath()\n{\n    var ANDROID_SDK_ROOT = Argument(\"android\", EnvironmentVariable(\"ANDROID_SDK_ROOT\") ?? EnvironmentVariable(\"ANDROID_HOME\"));\n\n    if (string.IsNullOrEmpty(ANDROID_SDK_ROOT)) {\n        throw new Exception(\"Environment variable 'ANDROID_SDK_ROOT' or 'ANDROID_HOME' must be set to the Android SDK root.\");    \n    }\n\n    return ANDROID_SDK_ROOT;\n}\n\npublic void PrintEnvironmentVariables()\n{\n    var envVars = EnvironmentVariables();\n\n    string path;\n    if (envVars.TryGetValue(\"PATH\", out path))\n    {\n        Information(\"Path: {0}\", path);\n    }\n\n    foreach(var envVar in envVars)\n    {\n        Information(","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/eng/cake/helpers.cake#L61-L97","documentation":"Thrown by GetAndroidSDKPath when both the ANDROID_SDK_ROOT and ANDROID_HOME environment variables (and the `android` argument) are null or empty. The Android SDK path is required for any adb/emulator/sdkmanager invocation in the build, so the script refuses to continue.","triggerScenarios":"Argument(\"android\", EnvironmentVariable(\"ANDROID_SDK_ROOT\") ?? EnvironmentVariable(\"ANDROID_HOME\")) resolves to an empty/null string. Note the lookup is case-sensitive on non-Mac and relies on the exact upper-case variable names.","commonSituations":"A new dev machine or CI agent where the Android SDK was installed by Android Studio but no env var was set; a shell rc file that exports the var only for interactive sessions; a typo in the variable name; the var set in a different case on macOS where env lookup is case-sensitive here.","solutions":["Set ANDROID_SDK_ROOT to your SDK root (e.g. ~/Library/Android/sdk on macOS, %LOCALAPPDATA%\\Android\\Sdk on Windows) in your shell profile and CI variables.","Alternatively pass it at invocation time: `--android=/path/to/sdk`.","Confirm with `echo $ANDROID_SDK_ROOT` (or the platform equivalent) that the value is non-empty in the same shell that runs cake.","If on macOS, remember env var lookup here is case-sensitive — export the exact upper-case name."],"exampleFix":"# before\n# (no env var set)\n# after\nexport ANDROID_SDK_ROOT=\"$HOME/Library/Android/sdk\"\nexport ANDROID_HOME=\"$ANDROID_SDK_ROOT\"","handlingStrategy":"validation","validationCode":"var ANDROID_SDK_ROOT = Argument(\"android\",\n    EnvironmentVariable(\"ANDROID_SDK_ROOT\") ??\n    EnvironmentVariable(\"ANDROID_HOME\") ??\n    (IsRunningOnWindows() ? @\"%LOCALAPPDATA%\\Android\\Sdk\" : \"~/Library/Android/sdk\"));\nif (string.IsNullOrEmpty(ANDROID_SDK_ROOT) || !DirectoryExists(ANDROID_SDK_ROOT))\n    throw new Exception($\"Android SDK not found at '{ANDROID_SDK_ROOT}'. Set ANDROID_SDK_ROOT.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set ANDROID_SDK_ROOT in shell profiles and CI variables for all platforms.","Add a preflight check that DirectoryExists(ANDROID_SDK_ROOT) before build/test targets.","Document the macOS case-sensitivity caveat for the env var name."],"tags":["android","android-sdk","environment","env-var","dependency"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}