SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable

684,931

Solution 1

Please follow below steps it work's for me:

  • Go to your react-native Project then go to android directory Create a file with following name:

local.properties

  • Open the file and paste your Android SDK path like below:

For windows users:

sdk.dir=C:\\Users\\UserName\\AppData\\Local\\Android\\sdk

Replace UserName with your pc user name . Also make sure the folder is sdk or Sdk. In my case my computer user name is Zahid so the path look like:

sdk.dir=C:\\Users\\Zahid\\AppData\\Local\\Android\\sdk

For Mac users:

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

Where USERNAME is your OSX username.

For Linux (Ubuntu) users:

sdk.dir = /home/USERNAME/Android/Sdk

Where USERNAME is your linux username(Linux paths are case-sensitive: make sure the case of S in Sdk matches)

In case if this doesn't work, add ANDROID_HOME variable in "Environment Variables" as C:\Users\USER\AppData\Local\Android\Sdk

enter image description here

Solution 2

The project might be missing a settings.gradle file. Make sure that file exists from the project you are importing. If not add the settings.gradle file with the following :

include ':app'

Save the file and put it at the top level folder in your project.

Solution 3

I know this answer is late, but I hope it helps others.

The answer is simple. You have to just copy your local.properties file to the folder where project is stored and it will work like charm. But remember, it must be placed in the root folder where the project is stored.

Solution 4

Please follow bellow points it work's for me:

  1. Go to your Project -> Android
  2. Create a file local.properties
  3. Open the file
  4. Paste your Android SDK path depending on the operating system:

    4.a Windows

    sdk.dir = C:/Users/USERNAME/AppData/Local/Android/sdk

    4.b Linux or MacOS

    sdk.dir = /home/USERNAME/Android/sdk

    Replace USERNAME with your user name

Solution 5

Check out in your local.properties file

sdk.dir=C\:\\Users\\USERNAME\\AppData\\Local\\Android\\sdk

properly write this format, and also check / slas using for path

Share:
684,931
Sameer Shamsudeen
Author by

Sameer Shamsudeen

Updated on July 08, 2022

Comments

  • Sameer Shamsudeen
    Sameer Shamsudeen 11 months

    I recently tried to import sample Android games I downloaded from Google's developer website. After importing them into Android Studio, I'm getting the following error:

    Error: SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

    What is this? I want to run the sample programs from Android Studio.

  • Sameer Shamsudeen
    Sameer Shamsudeen over 8 years
    I edited local.properties with this sdk.dir=C:\\Users\\sameer\\Android\\adt-bundle-windows-x86-2‌​0140702\\sdk, any error in this
  • Qutbuddin Bohra
    Qutbuddin Bohra over 8 years
    yeah after C put \ ... Svae with thishope done. sdk.dir=C\:\\Users\\sameer\\Android\\adt-bundle-windows-x86-‌​20140702\\sdk
  • George Papatheodorou
    George Papatheodorou almost 8 years
    This works nice with eclipse. Just create the file local.properties within the downloaded project and paste the sdk.dir . In my case it was : "sdk.dir=C\:\\adt-bundle-windows-x86_64-20140321\\sdk"
  • pblead26
    pblead26 almost 7 years
    But I have to copy it everytime? This seems like a hack than the correct approach
  • Harsh Mittal
    Harsh Mittal almost 7 years
    Its is the most easy solution for this problem as you dont have to change anything in project. There are also other solution in which you have to do change in code , but I think for such issue one cannot afford to waste much time.
  • Tot Zam
    Tot Zam over 6 years
    How can I tell if my project is missing settings.gradle? Where is that file usually stored? Where do I type include ':app'? What exactly does include ':app' do/generate? Can you please add more detail to your answer?
  • Joseph
    Joseph over 6 years
    @TotZam its stored in the root of your project
  • Tot Zam
    Tot Zam over 6 years
    Found it. Thanks. For future reference, where would I run include ':app'? I'm quite new to Android and trying to find my way around.
  • Joseph
    Joseph over 6 years
    You don't run include :app, if you are using Android Studio, that lets Android Studio add your project module so you can run it without further configuration. After you add the line in settings.gradle you will notice the Play button becomes active after gradle finishes building and downloading packages
  • Priyank Patel
    Priyank Patel over 6 years
    Put your project folder name instead of 'app' if it's different. It works.
  • user1147171
    user1147171 over 6 years
    This worked for me when I had this issue after downloading ExoPlayer 2.1.
  • Vinay Vissh
    Vinay Vissh over 6 years
    Thanks a lot! It helped in importing MPAndroidChart Example which was just stuck at this error :P
  • yashhy
    yashhy about 6 years
    if anyone facing You have not accepted the license agreements... error after the above step see here stackoverflow.com/a/41078173/1778834
  • yashhy
    yashhy about 6 years
    if anyone facing You have not accepted the license agreements... error after the above step see here stackoverflow.com/a/41078173/1778834
  • Rohan Gala
    Rohan Gala about 6 years
    I have installed android on my windows 10 m/c but there is no such folder sdk.dir=C\:\\Users\\USERNAME\\AppData\\Local\\Android?
  • Mayur Baldha
    Mayur Baldha about 6 years
    My android SDK is in D:\Tools\Android\ directory not in C:\ setting sdk.dir=D:\Tools\Android Doesn't work.
  • cesarsicas
    cesarsicas almost 6 years
    It works, but Shouldn't Intelij generate this automatically ? tks !
  • rommex
    rommex almost 6 years
    This does not work for me. The file is present, but I still have the error
  • Avi Cherry
    Avi Cherry almost 6 years
    This is often a symptom of attempting to open a project that's not standalone and relies on a parent project. So while this answer is correct, in some circumstances it won't help because most Android projects are reliant on a parent gradle project to for essential configuration.
  • Val
    Val about 5 years
    This corrected the issue on both the mac High Serria and Windows 10. Great answer and efficient.
  • soshial
    soshial about 5 years
    This is the only thing that helped me. Steps #3 and #4 are very important
  • cabanni
    cabanni almost 5 years
    what kind of content should be in the settings.gradle file?
  • user25
    user25 almost 5 years
    yes it was in sample folder not in project root, thanks!
  • Arhat Baid
    Arhat Baid almost 5 years
    @cabanni settings.gradle just includes the module in your application. By default it'll be 'app' module. Hope it helps/
  • Martijn
    Martijn over 4 years
    I already had an ANDROID_SDK which points to the same dir, so for me it was ANDROID_HOME=$ANDROID_SDK
  • macmuri
    macmuri about 4 years
    This error is also related with OS language(!!!). If you are using a OS language other than english than try to convert your OS language to english, I am sure it will work. This is only for Windows.
  • Michal Vician
    Michal Vician about 4 years
    This helped. After "Re-import Gradle Project" was launched, the following 2 errors were printed to console which helped me to detect the problem: Invalid Gradle JDK configuration found, Project JDK is not specified. So everything started to work after I fixed the JDK path in Settings.
  • Michal Vician
    Michal Vician about 4 years
    After JDK path was fixed I also had to restart the IDE with "File > Invalidate Caches / Restart ..." option.
  • Samuel Owino
    Samuel Owino almost 4 years
    This gives me " Plugin with id 'com.android.application' not found."
  • Joseph
    Joseph almost 4 years
    This seems to be a gradle issue, did you try this github.com/udacity/ud839_Miwok/issues/87
  • MING WU
    MING WU almost 4 years
    just open the android folder by android studio, when android studio opens the 'android' folder, local.properties will be created automatically.
  • Nauman Moazzam
    Nauman Moazzam over 3 years
    It is too late to comment, but i want to know how to do that in MacOS?
  • Innocent
    Innocent over 3 years
    i am working with open cv what should i do to add NDK?
  • Erik Sillén
    Erik Sillén over 3 years
    Thanks a lot! Had everything else set up but this was missing. A bit weird that Android Studio doesn't give a more understandable error.
  • Alexei Martianov
    Alexei Martianov over 3 years
    It helped. Actually this solution is hinted in the error wording itself. I use IntelliJ on Mac and in project structure I have SDK correct path. Why still do I need that in local.properties then?
  • Shuvo
    Shuvo over 3 years
    in MacOS you need to do same procedure just you need to find your Android SDK file path and paste it local.properties file...that's it
  • grc
    grc about 3 years
    After adding sdk.dir path and also to ~/.bashrc, nothing worked. But then I closed and opened again and it worked. Thanks!
  • groo
    groo almost 3 years
    This worked for me using IntelliJ with Android support installed.
  • Manish
    Manish over 2 years
    this answer is so underrated. I've come here twice now and it solved both the times. thanks a lot.
  • Md Shahnawaz
    Md Shahnawaz over 2 years
  • Shishir Shetty
    Shishir Shetty over 2 years
    RESTART is the key.
  • JSON derulo
    JSON derulo over 2 years
    If anyone is trying to run one of the samples in the facebook-android-sdk, this tip helped me run it. Loading only one of the examples doesn't work.
  • Anton Plebanovich
    Anton Plebanovich about 2 years
    I just went to File > Project Structure and it said that SDK location is incorrect and fixed it for me on MacOS
  • Kimanthi K.
    Kimanthi K. almost 2 years
    This is the answer bro. Big Up maaan!
  • Admin
    Admin over 1 year
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
  • Lama
    Lama over 1 year
    in windows it should be with double slashes like this sdk.dir = C:\\Users\\USERNAME\\AppData\\Local\\Android\\sdk
  • jave.web
    jave.web about 1 year
    if you're using eas build (expo build has been deprecated), this is no longer working, and you have to define the env variable in eas.json, also the path to the android SDK may be different (I don't have it in my home directory)
  • jave.web
    jave.web about 1 year
    EAS builds: use eas.json under build => production (or other mode) make sure you have { "env": { "ANDROID_SDK_ROOT": "/your/path/to/androidSDK" }
  • InsaneCat
    InsaneCat 12 months
    Working Solution :)