Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Gradle cannot find the Android SDK on this machine

ErrorSDK 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.

  • Applies to Android Gradle Plugin 8.x and 9.x, Gradle 8.x and 9.x, Flutter 3.44 stable, Android Studio current stable, macOS 26
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 differ
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2echo $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. 3local.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. 4flutter 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

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/.gitignore

2Fix

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/sdk

3Verify

The file now has an sdk.dir line and Gradle gets past configuration.

cat android/local.properties
cd android && ./gradlew help

Confirmed by developer.android.com

Did this fix it?

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 $0

2Fix

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-tools

3Verify

A new terminal prints the folder and adb is found in it.

echo $ANDROID_HOME
which adb

Confirmed by developer.android.com

Did this fix it?

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\\Sdk

3Verify

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 help

Confirmed by docs.oracle.com

Did this fix it?

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 get

3Verify

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.properties

Confirmed by github.com

Did this fix it?

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:

Related fixes

Mobile 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 fix

Mobile 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.