Fix "SDK location not found" (ANDROID_HOME / sdk.dir) on Android
SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable or by setting the sdk.dir path in your project's local properties file at '/path/to/project/android/local.properties'.
- SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at 'C:\Users\me\app\android\local.properties'.
- No Android SDK found. Try setting the ANDROID_HOME environment variable.
- Unable to locate Android SDK.
- Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'. > SDK location not found.
Gradle does not know where the Android SDK is installed. Put its path in android/local.properties with sdk.dir=..., or set the ANDROID_HOME environment variable, then open a new terminal and rebuild.
What this error means
The Android Gradle Plugin (AGP) needs the Android SDK (build-tools, platforms, platform-tools) to compile the app. When the build starts, it looks for its location in this order: the sdk.dir property in local.properties at the root of the Android project, then the ANDROID_HOME environment variable (and the legacy ANDROID_SDK_ROOT). If none is found, or the path points to a folder that does not exist, the build stops before compiling anything. It is very common on a freshly cloned project (local.properties is never committed), on a new machine, in CI, or when the build runs from a terminal that cannot see the variable.
Common causes
- Freshly cloned project:
local.propertiesis ignored by Git, so it does not exist on your machine yet andANDROID_HOMEis not set. - Variable set but not loaded: you added
ANDROID_HOMEto your shell profile, but the terminal, the IDE or the Gradle daemon were started before. - SDK never installed: you installed Android Studio without finishing the first-run wizard, or only the command-line tools.
- Invalid path:
sdk.dirpoints to an old location (another user, another machine) or contains unescaped backslashes on Windows. - Build running in CI or Docker with no SDK installed and no
ANDROID_HOMEin the job environment.
Step-by-step fix
-
Find the SDK path
In Android Studio: Settings (macOS: Android Studio > Settings) > Languages & Frameworks > Android SDK, field "Android SDK Location". Default locations: macOS
~/Library/Android/sdk, Windows%LOCALAPPDATA%\Android\Sdk, Linux~/Android/Sdk. Check that the folder containsplatform-toolsandplatforms.# macOS ls ~/Library/Android/sdk # Linux ls ~/Android/Sdk -
Create local.properties (quick fix)
Create
local.propertiesin the Android folder of the project (android/for React Native, Flutter or Capacitor, the root for a native Android project). On Windows,\and:must be escaped in this file.# macOS sdk.dir=/Users/YOUR_USER/Library/Android/sdk # Linux sdk.dir=/home/YOUR_USER/Android/Sdk # Windows sdk.dir=C\:\\Users\\YOUR_USER\\AppData\\Local\\Android\\Sdk -
Set ANDROID_HOME (macOS / Linux)
Lasting fix for all your projects: add the variable to your shell profile (
~/.zshrcon macOS,~/.bashrcon most Linux distributions), then open a new terminal.# ~/.zshrc (macOS) - on Linux use $HOME/Android/Sdk in ~/.bashrc export ANDROID_HOME="$HOME/Library/Android/sdk" export PATH="$PATH:$ANDROID_HOME/emulator:$ANDROID_HOME/platform-tools" -
Set ANDROID_HOME (Windows)
In PowerShell, save the variable for your user, then close and reopen the terminal and the IDE. You can also use "Edit environment variables for your account".
[Environment]::SetEnvironmentVariable("ANDROID_HOME", "$env:LOCALAPPDATA\Android\Sdk", "User") -
Install the SDK if it is missing
If the folder does not exist, open Android Studio and finish the wizard (or More Actions > SDK Manager) to install an Android platform, Build-Tools and Platform-Tools. Without Android Studio, use
sdkmanagerfrom the Command-line Tools.sdkmanager "platform-tools" "platforms;android-35" "build-tools;35.0.0" sdkmanager --licenses -
Stop the Gradle daemon and rebuild
The Gradle daemon keeps the old environment in memory. Stop it, then rebuild. For Flutter, also give the path to the tool and check with
flutter doctor.cd android && ./gradlew --stop && cd .. npx react-native run-android # Flutter flutter config --android-sdk "$ANDROID_HOME" flutter doctor -v
Did this fix work for you?
Confirm it in one click: it will rise for the next developers stuck on the same error.
Keep it from coming back
- Set
ANDROID_HOMEonce in your shell profile or Windows variables instead of recreatinglocal.propertieson every clone. - Keep
local.propertiesin.gitignore: it contains machine-specific paths and would break your teammates’ builds. - In CI, use an image or action that provides the SDK (GitHub Actions Ubuntu runners already expose
ANDROID_HOME) and document the expected platform version.
Frequently asked questions
ANDROID_HOME or ANDROID_SDK_ROOT?
ANDROID_HOME is the recommended variable today; ANDROID_SDK_ROOT is deprecated but still read. If you set both, they must point to the same folder.
Should I commit local.properties?
No. It contains the SDK path on your machine. Android Studio regenerates it automatically when you open the project.
Why does it work in Android Studio but not in the terminal?
Android Studio writes sdk.dir to local.properties or knows the SDK from its settings, while your terminal has no ANDROID_HOME. Add the variable to your shell profile and open a new terminal.
Useful tools for this error
More Mobile (Android, iOS) errors
- Fix "CocoaPods could not find compatible versions for pod" on iOS
- Fix "Unable to load script" (index.android.bundle) in React Native
- Fix "Signing for "App" requires a development team" in Xcode
- Fix "INSTALL_FAILED_UPDATE_INCOMPATIBLE: signatures do not match" on Android
- Fix "Duplicate class ... found in modules" in an Android Gradle build
- Fix "cmdline-tools component is missing" and "Android license status unknown" (flutter doctor)
- Fix "Invariant Violation: "main" has not been registered" (React Native / Expo)