Gradle cannot find the Android SDK on this machine
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 '…/local.properties'.Short answer
Gradle looks for the Android SDK in the sdk.dir line of android/local.properties and in the ANDROID_HOME environment variable, and found neither. Find the folder that SDK Manager calls Android SDK Location, then write it into local.properties or export it as ANDROID_HOME. In a Flutter app, flutter pub get recreates local.properties from Flutter's own SDK setting.
Fix it fast
1Find out which cause you have
Check the two places Gradle reads, and whether the SDK folder exists at all. The path to use is the Android SDK Location shown in Android Studio under Tools > SDK Manager.
echo "ANDROID_HOME=$ANDROID_HOME" grep sdk.dir android/local.properties || echo "no sdk.dir line" ls "$HOME/Library/Android/sdk/platform-tools" 2>/dev/null | head -3 # macOS default location; yours may differ2Match what you see, then jump to its fix
- 1
The path at the end of the message ends in local.properties and ls android/local.properties says no such filelocal.properties does not exist yet (fresh clone, new checkout, CI)Fix - 2
echo $ANDROID_HOME prints an empty line, or only ANDROID_SDK_ROOT is set; no sdk.dir line existsANDROID_HOME is not set in the shell or CI job that runs GradleFix - 3
local.properties has an sdk.dir line, but the folder is missing, was moved, or the path on Windows has single backslashessdk.dir points to a folder that does not exist, or its Windows backslashes are not escapedFix - 4
flutter doctor -v shows Unable to locate Android SDK, and local.properties has no sdk.dir after flutter pub getFlutter itself has no Android SDK configured, so it writes no sdk.dirFix
- 1
What does the error look like?
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 '…/local.properties'.FAILURE: Build failed with an exception. What went wrong: SDK location not found.
Cause 1 of 4
local.properties does not exist yet (fresh clone, new checkout, CI)
1Check
local.properties holds machine-specific settings for the build, among them sdk.dir, the path to the Android SDK. Flutter's template adds it to .gitignore, so a new clone has none. Check that the file exists beside settings.gradle.
ls android/local.properties
grep -n "local.properties" android/.gitignore2Fix
In a Flutter project run pub get; Flutter writes sdk.dir and flutter.sdk into android/local.properties from the SDK it uses. Without Flutter, create the file yourself with one line holding the absolute SDK path.
# Flutter project
flutter pub get
# plain Android project: android/local.properties (or ./local.properties)
sdk.dir=/Users/you/Library/Android/sdk3Verify
The file now has an sdk.dir line and Gradle gets past configuration.
cat android/local.properties
cd android && ./gradlew helpConfirmed by developer.android.com
Cause 2 of 4
ANDROID_HOME is not set in the shell or CI job that runs Gradle
1Check
ANDROID_HOME is the variable that tools read to find the SDK folder. ANDROID_SDK_ROOT, which pointed to the same folder, is deprecated, so a machine or CI image that only sets the old name relies on a deprecated variable. Variables you export in a terminal last only for that window unless you add them to your shell startup file.
echo "ANDROID_HOME=$ANDROID_HOME"
echo "ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT"
echo $02Fix
Export ANDROID_HOME with the SDK folder, add it to the startup file of your shell (for Zsh, ~/.zprofile), and put platform-tools on PATH. Open a new terminal afterwards.
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools3Verify
A new terminal prints the folder and adb is found in it.
echo $ANDROID_HOME
which adbConfirmed by developer.android.com
Cause 3 of 4
sdk.dir points to a folder that does not exist, or its Windows backslashes are not escaped
1Check
The value must be the real SDK folder. local.properties is read as a Java properties file, where a backslash is an escape character, so a Windows path needs doubled backslashes (a colon may be escaped too). Check that the folder in the file exists and holds platform-tools.
grep sdk.dir android/local.properties
ls "$(grep sdk.dir android/local.properties | cut -d= -f2)/platform-tools"2Fix
Copy the Android SDK Location from Tools > SDK Manager into the file. Use forward slashes or doubled backslashes on Windows. If the SDK folder is really gone, install the SDK through SDK Manager first.
# macOS or Linux
sdk.dir=/Users/you/Library/Android/sdk
# Windows (Java properties escaping)
sdk.dir=C\:\\Users\\you\\AppData\\Local\\Android\\Sdk3Verify
The folder listed by the check exists and Gradle starts.
ls "$(grep sdk.dir android/local.properties | cut -d= -f2)/platform-tools"
cd android && ./gradlew helpConfirmed by docs.oracle.com
Cause 4 of 4
Flutter itself has no Android SDK configured, so it writes no sdk.dir
1Check
Flutter takes the sdk.dir value for local.properties from the Android SDK folder it has found or has been told about. If flutter doctor cannot locate the SDK, the file gets none. Ask Flutter what it sees.
flutter doctor -v | grep -A4 "Android toolchain"2Fix
Tell Flutter where the SDK is, then regenerate the file with pub get. If you have no SDK yet, install one with Android Studio's SDK Manager first.
flutter config --android-sdk "$HOME/Library/Android/sdk"
flutter pub get3Verify
flutter doctor finds the SDK and local.properties has the sdk.dir line.
flutter doctor -v | grep -A2 "Android toolchain"
grep sdk.dir android/local.propertiesConfirmed by github.com
How do I stop it coming back?
- Keep local.properties out of version control; each machine writes its own.
- Set ANDROID_HOME once in the shell startup file and in the CI image instead of per command.
- Use ANDROID_HOME, not the deprecated ANDROID_SDK_ROOT.
- After cloning a Flutter app, run flutter pub get before the first Android build.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Mobile apps
Flutter Android build stops with Execution failed for task ':app:…'
Execution failed for task ':app:compileFlutterBuildRelease'.
The line only tells you which Gradle step broke; the task name in the quotes tells you why.
5 causes, each with a fixMobile apps
A phone is plugged in over USB but Android Studio and adb do not list it
adb devices prints List of devices attached with nothing below it
adb lists a phone only when four things hold: USB debugging is on, you accepted the computer's RSA key on the phone, the computer has a driver or udev rule for the device, and the cable carries data to a running adb server.
6 causes, each with a fixMobile apps
Google Play says the app does not support 16 KB memory pages
check_elf_alignment.sh reports UNALIGNED for a library under lib/arm64-v8a
Google Play requires apps that target Android 15 or higher and ship native .so libraries to run on devices with 16 KB memory pages; from 1 February 2027 it will block updates that do not.
5 causes, each with a fixMobile apps
Gradle cannot find com.google.firebase:firebase-analytics-ktx
Required by: project :app
Firebase moved the Kotlin extensions into the main modules and stopped releasing the -ktx modules in July 2025.
2 causes, each with a fixMobile apps
Gradle cannot create LibraryVariantBuilderImpl in a Flutter Android build
Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl
This error appears when the Android Gradle plugin (AGP) cannot run in the Gradle or IDE you use.
3 causes, each with a fixMobile apps
Flutter release build cannot open the keystore: HmacPBESHA256 not available
Algorithm HmacPBESHA256 not available
The keystore is a PKCS12 file protected by a newer algorithm than the Java that is reading it understands.
3 causes, each with a fix