59

Getting this complaint from IntelliJ 13:

8:15:48 PM Gradle '<project>' project refresh failed:
           SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
           Build file '/<project>/build.gradle' line: 20
           : Gradle settings

I have tried to spam my local.properties in every directory I can think of but still getting this error. What gives?

pfrank
  • 2,090
  • 1
  • 19
  • 26
  • [Have a look here?](http://stackoverflow.com/a/18660928/2591002) – SweetWisher ツ Dec 19 '13 at 04:24
  • I tried putting the file in my root directory already, still getting that error :( – pfrank Dec 19 '13 at 04:44
  • The local.properties file should be in the root of your project (as indicated in earlier comments here), in the same place as your settings.gradle file. You say you're using IntelliJ 13, presumably with the Android plugin, and not Android Studio? And this is obviously a Gradle-based project. Can you post more details about the directory structure of your project? Also, try building from the command line with the --info and --stacktrace options and post that output. – Scott Barta Dec 19 '13 at 17:09

3 Answers3

82

The local.properties file goes in the project's root level, in the same folder as the gradlew, gradlew.bat, settings.gradle and other files.

This file should not be included in source control. After (incorrectly) including this in source control, then deleting the file locally, Android Studio re-created the file for me automatically.

Here is the example content of this file:

## 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.
#Thu Aug 14 14:49:26 PDT 2014
sdk.dir=C\:\\Program Files (x86)\\Android\\android-studio\\sdk

Note the sdk.dir= reference to the location of the Android Studio SDK installation (which may be different on different machines).

CJBS
  • 15,147
  • 6
  • 86
  • 135
  • 1
    my `local.properties` is committed into source control. It's weird. – Saeed Neamati Jun 04 '16 at 05:35
  • 10
    @SaeedNeamati It shouldn't be, as it contains configuration that's specific to a workstation (i.e. not everyone's SDK is going to be installed in the same location, especially if doing cross-platform development) – CJBS Jun 04 '16 at 05:39
  • 2
    add it to your .gitignore file. you can put an example.local.properties file in that location. – agm1984 Oct 03 '17 at 21:55
  • Is this file included when creating APK? – Mr. Nacho Jan 17 '18 at 09:52
  • 1
    @Mr.Nacho - this file shouldn't be included, as it's a config file specific to a development workstation, not the output package. – CJBS Jan 17 '18 at 17:44
  • Android studio automatically creates this file if it does not exist when opening a project. After opening a project, use File, Project Structure, SDK Location box to set the location of the android sdk on your local machine. – farid_z Jul 15 '19 at 19:05
  • How serious should we take that warning? – AndreKR Jan 30 '22 at 03:14
  • does this file goes into the apk? – Mohsin Falak Sep 27 '22 at 09:57
21

For MAC create file local.properties inside android/ and paste this line inside the file

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

Tunvir Rahman Tusher
  • 6,421
  • 2
  • 37
  • 32
1

For MacOS, put your file gradle.properties in these 2 places:

  1. ~/.gradle/
  2. /Users/<your_user>/Library/sdk/
Rafael Baptista
  • 336
  • 2
  • 7