PC パソコン

Causes and Solutions for Android Studio “SDK location not found”

When you open a project in Android Studio or run Gradle Sync,
an error called “SDK location not found” may be displayed.

This error occurs when Android Studio or Gradle cannot determine the location where the Android SDK is stored.
The main possible causes include the Android SDK not being installed,
a problem with the local.properties settings,
a change in the SDK path,
or environment variables not being configured correctly.

This article explains the main causes and solutions for the “SDK location not found” error in Android Studio.

What Is “SDK location not found”?

“SDK location not found” is an error displayed when Gradle cannot determine the location of the Android SDK.

For example, an error like the following may be displayed.

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

In this case, the error may occur not only when the Android SDK itself does not exist,
but also when the settings indicating the location of the Android SDK are not being read correctly.

Main Causes

The main causes of “SDK location not found” in Android Studio include the following.

  • The Android SDK is not installed
  • local.properties does not exist
  • The sdk.dir setting in local.properties is incorrect
  • The storage location of the Android SDK has been changed
  • The project was copied from another PC
  • local.properties is not included in a project obtained from Git or another source
  • The ANDROID_HOME environment variable is not set
  • An old SDK path remains in the environment variables
  • The SDK folder has been deleted or moved
  • There is an error in the way the path is written

Point:
“SDK location not found” does not mean that the Android SDK version is incompatible.
It is an error indicating that Gradle cannot determine the location where the Android SDK is stored.

Check Whether the Android SDK Is Installed

First, check whether the Android SDK is installed in Android Studio.

Open the SDK Manager in Android Studio and check the storage location of the Android SDK
and whether the required SDK Platform and SDK Tools are installed.

If the Android SDK itself is not installed,
install the required SDK from the SDK Manager.

Check the Android SDK Storage Location

In Android Studio, you can check the location where the Android SDK is stored.

Check the Android SDK Location displayed in the SDK Manager or elsewhere,
and confirm that the folder actually exists.

The SDK location varies depending on the environment.

For example, on macOS, a location like the following may be used.

/Users/username/Library/Android/sdk

On Windows, a location like the following may be used.

C:\Users\username\AppData\Local\Android\Sdk

Check local.properties

In an Android project,
the location of the Android SDK may be specified in
local.properties
in the project root directory.

For example, it may be configured as follows.

sdk.dir=/Users/username/Library/Android/sdk

On Windows, depending on the environment, it may be written as follows.

sdk.dir=C\:\\Users\\username\\AppData\\Local\\Android\\Sdk

Check whether the location specified in sdk.dir
matches the actual storage location of the Android SDK.

If local.properties Does Not Exist

If local.properties does not exist,
Gradle may be unable to determine the location of the Android SDK,
causing “SDK location not found” to occur.

Reopening the project in Android Studio may automatically create
local.properties in some environments.

If it is not created automatically,
create local.properties in the project root directory
and specify the correct location of the Android SDK.

Check a Project Copied from Another PC

If you copied an Android project from another PC,
the SDK path from the original PC may remain in local.properties.

For example, even if the location on the original PC was as follows,

sdk.dir=/Users/user1/Library/Android/sdk

the Android SDK may not exist in the same location on the destination PC.

Check the Android SDK Location on the PC you are currently using,
and correct the sdk.dir setting in local.properties.

Check a Project Obtained from Git

If you obtain an Android project from GitHub or another source,
local.properties may not be included.

Because local.properties contains paths for the local environment of each PC,
it is usually excluded from Git version control.

Therefore, on the PC where the project was obtained,
you need to prepare a local.properties file that matches the location of your Android SDK.

If You Changed the SDK Location

If you moved the Android SDK folder,
“SDK location not found” may occur if the previous location remains in
local.properties or the environment variables.

Check the current storage location of the SDK
and change settings such as sdk.dir to the new path.

Check the ANDROID_HOME Environment Variable

Depending on the environment,
ANDROID_HOME
may be set to indicate the location of the Android SDK.

For example, on macOS or Linux, it may be configured as follows.

export ANDROID_HOME=$HOME/Library/Android/sdk

On Windows, the Android SDK path may be configured as an environment variable.

If ANDROID_HOME is set,
check whether the specified location matches the actual location of the Android SDK.

Check Whether an Old Path Remains in ANDROID_HOME

If the Android SDK was previously stored in a different location,
an old path may remain in the ANDROID_HOME environment variable.

If it refers to an old SDK path,
change it to the location of the Android SDK currently being used.

Check ANDROID_SDK_ROOT

Depending on the environment,
ANDROID_SDK_ROOT
may be set.

If multiple environment variables related to the Android SDK specify different locations,
inconsistencies in the settings may cause problems.

Check whether the Android SDK Location displayed in Android Studio
matches the contents of the environment variables.

Check for Errors in the Path

If the SDK path specified in local.properties
contains a spelling mistake or is written incorrectly,
the SDK cannot be recognized.

On Windows in particular,
pay attention to how backslashes are written.

sdk.dir=C\:\\Users\\user\\AppData\\Local\\Android\\Sdk

Check whether the specified folder actually exists.

Check the Location of local.properties

local.properties is normally placed in the root directory of the Android project.

If it is created in another folder,
Gradle may not be able to read it correctly.

Check whether it is located near the project root where
settings.gradle, settings.gradle.kts, and related files are located.

Check the local.properties File Name

If the file name is
local.properties.txt
or something similar,
Gradle cannot recognize it as local.properties.

Check that the file name is exactly
local.properties.

Run Gradle Sync Again

After correcting the SDK location or local.properties,
run Gradle Sync again.

Run
Sync Project with Gradle Files
or a similar option from Android Studio.

If the settings have been corrected properly,
Gradle may recognize the Android SDK and synchronize successfully.

Restart Android Studio

If changes to the SDK storage location or environment variables are not reflected,
restart Android Studio.

In particular, if you change environment variables,
the new settings may not be reflected while Android Studio remains open.

Restart the Terminal as Well

If you change environment variables on macOS, Linux, or another environment,
old environment variables may remain in an open Terminal.

Open a new Terminal
and run the Gradle command again as necessary.

Recreate local.properties

If you cannot determine whether there is a problem with the contents of
local.properties,
one option is to recreate the file after checking the current file.

Check the correct location of the Android SDK
and set sdk.dir as follows.

sdk.dir=/correct/Android/SDK/path

Run Gradle Sync after recreating the file.

Check Whether the Android SDK Has Been Deleted

Even if the path in local.properties appears to be correct,
the specified folder itself may have been deleted.

Check the SDK folder using Finder, File Explorer, or another file manager,
and confirm that the Android SDK actually exists.

If the SDK does not exist,
reinstall it using the SDK Manager in Android Studio or another method.

Check the SDK Location in SDK Manager

If you do not know where the SDK is located,
use the Android SDK Location displayed in the Android Studio SDK Manager as a reference.

Compare that path with the sdk.dir setting in
local.properties,
and correct it if they are different.

When Building from the Command Line

Android Studio may work normally,
while “SDK location not found” occurs only when Gradle is run from the Terminal.

In this case, check not only local.properties,
but also the environment variables loaded by the Terminal.

Check whether Android Studio and the Terminal are using different environment settings.

If It Occurs in a CI or Automated Build Environment

In a CI or automated build environment,
local.properties may not exist, unlike on a development PC.

The Android SDK may also be installed in a different location.

Check whether the Android SDK is installed in the CI environment,
and whether the SDK path and environment variables are configured for that environment.

What to Check for Each Situation

The details displayed together with “SDK location not found”
can help narrow down what should be checked.

Situation Main Points to Check
local.properties does not exist Create the file, configure sdk.dir
The location specified by sdk.dir does not exist Android SDK Location, SDK moved or deleted
Copied from another PC Whether the SDK path from the original PC remains
Obtained from Git Create local.properties
Environment variables were changed ANDROID_HOME, ANDROID_SDK_ROOT, restart
Only the Terminal fails Environment variables on the Terminal side
Only CI fails SDK installation location and environment variables in the CI environment

Steps to Check If the Problem Is Not Resolved

If you do not know the cause, checking the following in order makes it easier to narrow down the problem.

  1. Check the Android SDK Location in the Android Studio SDK Manager
  2. Check whether that SDK folder actually exists
  3. Check whether local.properties exists in the project root directory
  4. Check whether sdk.dir specifies the correct SDK location
  5. Check whether an SDK path from another PC remains
  6. Check whether the file name is exactly local.properties
  7. Check ANDROID_HOME
  8. If ANDROID_SDK_ROOT is set, check its contents
  9. Check whether the SDK has been moved or deleted
  10. Run Gradle Sync again
  11. Restart Android Studio
  12. If you changed environment variables, reopen the Terminal as well
  13. Reinstall the Android SDK if necessary

Important:
If “SDK location not found” is displayed,
first check the current Android SDK Location in Android Studio
and confirm that it matches the sdk.dir setting in local.properties.

Summary

Android Studio’s
“SDK location not found”
is an error displayed when Gradle cannot determine the storage location of the Android SDK.

It may be caused not only by the Android SDK not being installed,
but also by a missing local.properties file,
an incorrect sdk.dir,
moving the SDK,
copying a project from another PC,
or environment variable settings such as ANDROID_HOME.

First, check the correct Android SDK Location in the Android Studio SDK Manager
and confirm that it matches the sdk.dir configured in the project’s local.properties.
Then check the environment variables and whether the SDK folder exists
to efficiently narrow down the cause.