Debugging log · Gradle
"SDK location not found" on a fresh clone
I cloned one of my own projects onto a second machine, opened it, hit build — and Gradle stopped immediately complaining it couldn't find the Android SDK. Nothing was wrong with the code; it built fine on the machine I'd just come from. The missing piece was a small file that, by design, never travels with the repository.
The short version: Gradle finds your SDK through local.properties (or the ANDROID_HOME environment variable). That file is machine-specific and is deliberately excluded from Git, so a fresh clone has no idea where your SDK lives. Point it at the SDK on this machine and the build proceeds.
The error
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.
The message actually tells you both fixes. It's just not obvious why the setting vanished, which is what makes this confusing the first time.
Why local.properties isn't in the repo
The SDK path is different on every machine — a different drive on Windows, a different home directory on macOS, a different user on a CI runner. Committing one person's absolute path would break the build for everyone else, so the standard Android .gitignore excludes local.properties on purpose. That's correct behavior, not an oversight: the file is local configuration, which is exactly what its name says. Every fresh clone is expected to generate or supply its own.
Fix 1 — let Android Studio do it
The easiest path: open the project in Android Studio and let it sync. When Studio knows where your SDK is, it writes local.properties for you and the error disappears. If Studio itself doesn't know, set the path in File → Project Structure → SDK Location, and it'll write the file from that.
Or write it yourself
Create local.properties in the project root (next to settings.gradle) with one line:
# macOS / Linux sdk.dir=/Users/you/Library/Android/sdk # Windows — note the escaped backslashes sdk.dir=C\:\\Users\\you\\AppData\\Local\\Android\\Sdk
The Windows escaping trips people up: this is a Java properties file, so backslashes and the drive colon need escaping. A single unescaped path is a very common reason the file exists but "doesn't work".
Fix 2 — set ANDROID_HOME instead
For CI, Docker, or command-line builds where nobody's opening Studio, an environment variable is the cleaner answer:
export ANDROID_HOME=/path/to/android/sdk # macOS / Linux setx ANDROID_HOME "C:\Users\you\AppData\Local\Android\Sdk" # Windows
Gradle checks this when local.properties has no sdk.dir. It's the right mechanism for build servers, because it keeps the path in the environment rather than in a file someone might accidentally commit.
Don't "fix" this by committing your local.properties. It works on your machine and breaks on everyone else's — including your CI. Keep it ignored and let each environment supply its own path.
If it still fails after setting the path
- Check the path actually exists and points at the SDK root — the folder containing
platforms/andbuild-tools/, not one of them. - Check for typos and escaping on Windows, where an unescaped backslash silently produces a path Gradle can't resolve.
- Restart the terminal or Studio after setting an environment variable, since existing processes won't see it.
- Confirm the SDK is installed at all — on a brand-new machine you may need to install it via Studio's SDK Manager first.
Paths above are examples — substitute the SDK location on your own machine.