45

I have seen this same thing posted quite a few times, but whenever I try to import my project to my new work laptop I keep getting this error.

I have pulled the project from git (which his btw running fine on my old laptop).

Then I went to the sdk manager, downloaded all the tools, and all the SDK's available. In the welcome screen, I went to Configure -> project Defaults -> Project structure. Android SDK Tab says the path for projects without local.properties will be /Applications/Android Studio.app/sdk This is correct. Under SDKs I have all the available SDK's visible. Project SDK is set to API 18

Yet still I get this error when trying to build my project. Can anyone tell me where I havent looked yet?

I am running gradle 1.7 when trying to build which is downloaded from services.gradle.org

  • I don't have issues changing the path I know how to do this as I stated above. It's all set correctly. – Mathijs Segers Oct 9 '13 at 13:04
  • 1
    @MathijsSegers Please check if the settings.gradle file is contained in the root folder of the project. – JJD Mar 16 '14 at 17:57
  • It was, also it has been fixed by something random been a long while now. – Mathijs Segers Mar 16 '14 at 18:22
  • how did u fix the issue?..now I am facing the same issue.. – sarath Jun 3 '15 at 9:51

13 Answers 13

50

I had very similar situation (had a project on another machine and cloned it to my laptop and saw the same issue) and I looked in it.

Error message was coming from Sdk.groovy of Android gradle plugin: https://android.googlesource.com/platform/tools/build/+/master/gradle/src/main/groovy/com/android/build/gradle/internal/Sdk.groovy

By looking at code, its findLocation needs to set androidSdkDir variable and there are only three ways to do it:

  • create local.properties file and have either sdk.dir or android.dir line.
  • have ANDROID_HOME environment variable defined.
  • System.getProperty("android.home") - I'm not sure how it works, but it seems like a Java thing.

While your Android Studio knows that the SDK is at that place, I doubt that Android Studio is passing that information to gradle and thus we're seeing that error.

I created local.properties file at the project root and put the following line and it compiled the code successfully.

sdk.dir = /Applications/Android Studio.app/sdk/

|improve this answer|||||
  • Oh it's still open, appearantly we resolved it by copying all files from the old machine instead of using git........... so still no idea why but itś resolved. – Mathijs Segers Nov 6 '13 at 13:09
  • 1
    sometimes Android Studio doesn't read the ANDROID_HOME env var and if it does this, you just need local.properties which Android Studio normally builds but doesn't always... – kenyee Feb 18 '14 at 15:09
  • 1
    Note that on windows, a full path doesn't seem to work (i.e. c:\whatever\sdk). It seems to need to be on the same drive and an absolute path off of the root (i.e. /whatever/sdk) – Timothy Lee Russell May 14 '14 at 23:53
  • I'm going to accept this answer since it has most upvotes. Our project did origin from Eclipse I'd probably be able to find out wat was wrong back then but this looks like the possible issue and should be the most common issue out there. – Mathijs Segers Apr 17 '15 at 8:16
  • and don't forget to restart entire android studio – kreker Jun 29 '16 at 16:57
0

In my specific case I tried to create a React Native app using the react-native init installation process, when I encountered the discussed problem.

FAILURE: Build failed with an exception.

* What went wrong:

A problem occurred configuring project ':app'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at 'C:\Users\***\android\local.properties'.

I add this, because when developing an android app using react native, the 'root directory' to which so many answers refer, is actually the root of the android folder (and not the project's root folder, where App.js resides). This is also made clear by the directory marked in the error message.

To solve it, just add a local.properties file to the android folder, and type:

sdk.dir=C:/Users/{user name}/AppData/Local/Android/Sdk

Be sure to add the local disk's reference ('C:/'), because it did not work otherwise in my case.

|improve this answer|||||
0

If you have cloned a project from GitHub for example, and you've tried the methods mentioned here without success including:

  • Editing sdk.dir in the local.properties
  • Trying to set ANDROID_HOME environment variable
  • Or adding an alias as kasiara mentioned

You should try to see if you are trying to build a directory project that is a part within a bigger project, and so it may cause problems. So load the entire project, and then run the project directory you'd like.

|improve this answer|||||
0

You have also to ensure you have the correct SDK platform version installed in your environment by using SDK Manager.

|improve this answer|||||
2

To fix this problem, I had to define the ANDROID_HOME environment variable in the Windows OS.

To do this, I went to the System control panel.
I selected "Advanced system settings" in the left column.
On the "Advanced" tab, I selected "Environment Variables" at the bottom.

Here, I did not have an ANDROID_HOME variable defined. For this case, I selected "New..." and:
1) for "Variable name" I typed ANDROID_HOME,
2) for "Variable value", I typed the path to my SDK folder, e.g. "C:\...\AppData\Local\Android\sdk".

I then closed Android Studio and reopened, and everything worked.

Thanks to Dibish (https://stackoverflow.com/users/2244411/dibish) for one of his posts that gave me this idea.

|improve this answer|||||
0

I noticed that I get this error when I'm working on a new computer if I try to build from the command line first. However, if I build from Android Studio, it retrieves the SDK and creates the directory automatically. Then when I build from the command line it works.

|improve this answer|||||
  • Android Studio might also be generating a local.properties file with a sdk.dir parameter that's pointing to the Android SDK. – Michael Osofsky Mar 27 '18 at 17:57
2

If none of the answers work for you which happened to me on macbook pro in one of the projects you can always try to run Android Studio with an alias command passing sdk.dir with each run:

alias studio='launchctl setenv ANDROID_HOME '\''/Users/username/Library/Android/sdk'\'' && open -a '\''Android Studio'\'''
|improve this answer|||||
  • An example as for how to pass the alias can help, please – Hatzil Jan 14 '19 at 19:07
0

Copy and paste the local.properties file from a project you created on your new computer to the folder containing the project from your old computer also works too if you don't want to (or know how to) create a new local.properties file.

|improve this answer|||||
  • May not work if the local.properties file fully specifies the path including the name of the user on the original machine. – Michael Osofsky Mar 27 '18 at 17:58
11

creating local.properties file in the root directory solved my issue I somehow lost this file after pulling from GitHub

this is how my local.properties file looks like now:

## 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.
#Sat Feb 06 11:53:03 EST 2016

sdk.dir=/Users/****/Library/Android/sdk
|improve this answer|||||
1

specifying sdk.dir=<SDK_PATH> in local.properties in root folder solved my problem.

|improve this answer|||||
4

I found the solution here:

http://xinyustudio.wordpress.com/2014/07/02/gradle-sdk-location-not-found-the-problem-and-solution/

Just create a file local.properties and add a line with sdk.dir=SDK_LOCATION

|improve this answer|||||
0

I clone libgdx demo, can't import project. it also reminds like this.

Env:

Eclipse(Android-ADT)

window 7

so I create local.properties file at the project root, like following

sdk.dir = D:/adt-bundle-windows-x86/sdk

I hope this can help others!

|improve this answer|||||
1

Had the same problem in IntelliJ 12, even though I have ANDROID_HOME env variable it still gives the same error. I ended up creating local.properties file under the root of my project (my project has a main project w/ a few submodules in its own directories). This solved the error.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.