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 anANDROID_HOME
environment variable.
What is this? I want to run the sample programs from Android Studio.
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.
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.
Please follow below steps it work's for me:
- Go to your react-native Project then go to android directory Create a file with this 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
This problem is encountered when you try to import an Android Studio project from the ../app/build.gradle file.
Import the project by selecting the ../build.gradle file located in the root directory of your project.
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
Here is a work around for the problem when you click "Run App" (green arrow) and get the **Error:
Please select Android SDK** in the Edit Configuration dialog.
Open:
- File
/Settings/Appearance
andBehavior/System Settings/Android
SDK - Look at the top for Android SDK Location:
path to your SDK
Edit - Click the
Edit
button - Hit Next, Next, Finish to accept the defaults
This seems to save away the SDK location - even though nothing has changed - into some internal location. I inspected the .idea
and .gradle
folders but didn't see what Studio did to change a config file - but now I can run the app.
And to summarize the previous fixes - these are normally OK for a repo without build problems:
local.properties file is copied into the root folder by Studio
the path in the local.properties file has the correct path to the android SDK - in my case it is
sdk.dir=C:\\android\\sdk
(note that this path has a different format - Studio should write this file for you based on the Text Entry field in the Android SDK Settings dialog)settings.gradle file is present in the repo - and references the application folder (typically :app)
Please follow bellow points it work's for me:
- Go to your
Project -> Android
- Create a file
local.properties
- Open the file
paste your Android SDK path like below :
sdk.dir = C:/Users/USERNAME/AppData/Local/Android/sdk
Replace USERNAME
with your user name
In Linux:
If you have already downloaded the android SDK but its not being found.
The problem might be that the file local.properties
needs to be inside the same directory as gradle
stuff for gradle
to find it when building and running adb.
For my react-native project using gradle
I needed to put the local.properties
file to Myprojectname/android/
folder.
As I had unzipped the SDK to Downloads so I just use that path in the file with a row like this:
sdk.dir=/home/USER/Downloads/android-sdk-linux
I resolved this issue by creating ANDROID_HOME environment variable as follows in windows.
ANDROID_HOME=C:\Users\<user_name>\AppData\Local\Android\sdk
Restart Android Studio it should build project!
If you are trying to run Google android sample code, try to import the entire repository instead of an individual sample.
Here is the relevant section from instructions.html, included with the Google Calendar API sample code
- Import calendar-android-sample project
- Select "Import Project..." or File > Import Project...
- Select [someDirectory]/google-api-java-client-samples/build.gradle and click OK.
- Note: it will not work if you try to import [someDirectory]/google-api-java-client-samples/calendar-android-sample/build.gradle
- Select "Use local gradle distribution" with "Gradle home" of [someDirectory]/gradle-2.2.1 and click OK.
Just Remove .idea folder and import the project again. It's worked for me.
There is not a single reason for this error.
settings.gradle
may be missing or the content in it may be wrong.local.properties
may be missing or the sdk path may be wrongly written.
the best and the easiest way is to create new Android project move "app" folder from non working project to that newly made one and add the needed dependencies in the gradle of your new project and everything will work perfectly )
put these two lines in your .bashrc file and run source ~/.bashrc
export ANDROID_HOME=/Users/$USER/Library/Android/sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
For linux I did this.(For the first line)
export ANDROID_HOME=/home/$USER/Android/Sdk
For Mac/Linux users
You need to add ANDROID_HOME
to your path, add the following to your .bashrc || .zshrc || .profile
file
# change $HOME to the path where you installed android Sdk
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
Then run
$ source ~/.bashrc || .zshrc || .profile
Found working solution for me. Without adding local.properties and set up ANDROID_HOME variable. Seems like a bug in Android Studio and Intellij IDEA. You just need to ask IDE to "reset" path to Android SDK. 'SDK Location not found' in Android Studio despite having the environment variable set correctly
create a local.properties file in your root directory of your project with the following content
## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Tue Oct 24 17:40:53 CEST 2017
sdk.dir=/Users/****/Library/Android/sdk
I got this error after freshly cloning a repository. I expected local.properties to be generated automatically, but it wasn't. I was able to generate it by re-importing the Gradle project.
File > Re-import Gradle Project
If all else fails, copy the local.properties
file to the root of the project directory. Simply.
Anyone using Jenkins, might get it useful
You need to define a global variable name ANDROID_HOME
with the value of the path to android sdk.
For mac, it is /Users/YOUR_USER_NAME/Library/Android/sdk
If you have this problem when you pull a react-native project, you just need to open the android project with Android Studio. Everything you need will be automatically created.
- Open Android Studio
- File -> Open
- Choose the
android
folder under your react-native project folder - Wait for AndroidStudio to complete setup
- You can now close Android Studio
Check, 1. In Module settings, whether, SDK location is proper. 2. If Yes, check for local.properties file (Not the one placed inside app module, but the one placed outside the app module, at parent level). If not present add it with below lines inside it.
sdk.dir=/path/to/sdk/../Android/Sdk
I just faced the issue when I cloned my repo from Github and ran ./gradlew clean assembleDebug
. I confirm I have ANDROID_HOME in my .bashrc file.
So, I imported the project into Android Studio. Noticed that extension of my settings.gradle file is .kts
, settings.gradle.kts
. When I am done with import then I ran ./gradlew clean assembleDebug
and didn't get any issue.
I tried
sdk.dir = \Users\OLUWAGBEMIGA\AppData\Local\Android\sdk
and it worked, I simply pasted it in the project folder and outside.
In the environment variable I also used the sdk link above and the name ANDROID_HOME
as the path name. Close everything reopen and Cabom it all worked
I find My Solution too. I just Sync Gradle I have all folders (settings .gradle,..
) but I take this error .. I just Run Sync Project With Gradle File
and EditSdkLocation
And be ok ...
This solution actually works for me.. go to this pc -> properties -> advanced system settings -> environment variables -> then in system variable create new variable with name ANDROID_SDK_ROOT and value C:\Users{USERNAME(Replace it with your username}\AppData\Local\Android\Sdk
and make sure that if real android mobile using usb debugging is enabled. (very important)
then close cmd and restart it should work.
i was thinking your setting.gradle file is missing. Copy this file another project and paste your project.It will work i think.
in setting.gradle file ,
include ':app'
thats all. Have a good day.
You should download The Android SDK.
Use this link to download it.
Then you should define its location to Android Studio. Follow the steps:
- File->project Structure into Project Structure
- Left > SDK Location
- SDK location select Android SDK location (old version use Press +, add another sdk)
Good luck.
来源:https://stackoverflow.com/questions/27620262/sdk-location-not-found-define-location-with-sdk-dir-in-the-local-properties-fil