SDK location not found - Android Gradle Plugin SDK path resolution during Android Studio Gradle sync
0 reputation · 25 Dec 2022, 15:42 UTC
0 reputation · 25 Dec 2022, 15:42 UTC
The Android Gradle Plugin resolves the Android SDK location for project sync through local.properties sdk.dir and the ANDROID_SDK_ROOT environment variable. Android Studio records the selected SDK path in local.properties when configured via Settings, while Gradle builds may rely on the environment variable when local.properties is absent.
Uncertainty remains about the resolution precedence and failure mode when the SDK location is undefined. The sync behavior for a missing SDK location can differ between Android Studio releases and Android Gradle Plugin versions, and the handling of ANDROID_SDK_ROOT by the embedded Gradle daemon versus terminal builds is not consistently documented. It is unclear whether a missing location should hard-fail sync or trigger an automatic SDK download prompt.
What is the documented precedence between sdk.dir in local.properties and ANDROID_SDK_ROOT for Android Gradle Plugin SDK path resolution? Under which version conditions does a missing SDK location cause a hard failure of Gradle sync versus an offer to install the SDK? How does Android Studio propagate ANDROID_SDK_ROOT to its embedded Gradle daemon across operating systems?
AGP resolves the SDK location in a fixed order: local.properties sdk.dir first, then ANDROID_HOME, and finally the legacy ANDROID_SDK_ROOT. A project-level local.properties entry overrides any environment variable.
If none of these sources define a path, AGP throws a hard configuration error and Gradle sync fails. Android Studio may show a separate prompt offering to download or install an SDK, but that is an IDE action; Gradle sync itself does not auto-resolve the missing path.
ANDROID_SDK_ROOT is deprecated in favor of ANDROID_HOME. Newer AGP releases may emit warnings or drop support entirely. The exact version where this changes is not fixed across all releases, so confirm with the AGP release notes for your project.
Android Studio does not inject ANDROID_SDK_ROOT. The embedded Gradle daemon inherits the IDE process environment.
Windows: User and system environment variables are inherited, but edits require a full Android Studio restart.macOS / Linux: Launching from a GUI launcher often skips shell profiles. Variables set only in .zshrc or .bashrc may not reach the daemon unless the IDE is restarted from a terminal or the variable is set at the session level.local.properties exists with a valid sdk.dir, or set ANDROID_HOME before launching the IDE.ANDROID_SDK_ROOT, add a temporary Gradle task printing System.getenv('ANDROID_SDK_ROOT') to verify the daemon sees it.Which AGP version is the project using? That determines whether ANDROID_SDK_ROOT is still honored or should be migrated to ANDROID_HOME / local.properties.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.