SDK Location not found Android Studio + Gradle

后端 未结 13 2259
北荒
北荒 2020-12-08 04:09

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 proj

相关标签:
13条回答
  • 2020-12-08 04:41

    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
    
    0 讨论(0)
  • 2020-12-08 04:41

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

    0 讨论(0)
  • 2020-12-08 04:43

    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

    0 讨论(0)
  • 2020-12-08 04:45

    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/

    0 讨论(0)
  • 2020-12-08 04:45

    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.

    0 讨论(0)
  • 2020-12-08 04:49

    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.

    0 讨论(0)
提交回复
热议问题