55

I just updated Android Studio, and now when I try to build my app, I get the following Gradle error:

Information: Compilation completed with 2 errors and 0 warnings in 28 sec
Information: 2 errors
Information: 0 warnings
Error: Gradle: : java.lang.NullPointerException
/Users/mhuggins/Sites/SmoothieFlow/build.gradle
    Error:(9, 0) Gradle: A problem occurred evaluating root project 'SmoothieFlow'.
                 > The SDK directory '/Users/mhuggins/Library/Caches/AndroidStudioPreview/compile-server/"/Applications/Android Studio.app/sdk"' does not exist.

Details about Android Studio version:

Android Studio (I/O Preview) AI-130.709792

Build #AI-130.709792, built on June 14, 2013

JDK 1.6.0_43

VM: Java HotSpot(TM) 64-Bit Server VM by Apple Inc.

Does anyone know why I'm getting this and what I can do to fix it?

Matt Huggins
  • 81,398
  • 36
  • 149
  • 218
  • 1
    Try setting ANDROID_HOME env variable point to your SDK root. I'm not sure if this will help though. It helped me but the problem was different. – Alexander Kulyakhtin Jun 15 '13 at 15:46
  • Seems to be some misconfiguration to SDK references. Click on **SDK Manager** in Android Studio toolbar and check if all the references are correct. – Dhrubajyoti Gogoi Jun 15 '13 at 15:50
  • Looks like I'm not the only one getting this: https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=56628 – Matt Huggins Jun 15 '13 at 17:35

11 Answers11

136

Try adding a new file in the root of your project called "local.properties" (or modify the existing one). It should contain

sdk.dir= 

followed by the path to the sdk location, in my case

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

I think Android Studio normally creates one automatically but says that it shouldn't be added to VCS. I put it in my .gitignore and cloned the project on my Mac which resulted in this error. Strangely before 0.1.5 it worked just fine without the file.

buddahbrot
  • 1,278
  • 1
  • 11
  • 8
  • 2
    For project with multiple modules, check that the file is at the root of the project: it seems it is not picked up if it is in the module folder (as it was if migrating from Eclipse) – etienne Jun 21 '13 at 08:22
  • Cool. I had the same problem too. Having a `local.properties` local settings pointing to the `sdk.dir` solves it. – Calvin Cheng Jun 24 '13 at 03:49
  • 1
    According to the bug tracker, this has been fixed in the code for a future release. https://android-review.googlesource.com/#/c/61320/ – Matt Huggins Jun 27 '13 at 19:33
  • 1
    can we use a environment or a gradle variable here rather than hard-coding it? – Dheeraj Bhaskar Sep 06 '13 at 23:39
  • 1
    I had this same issue, but with "ndk.dir". This worked for me! Thanks! – Thomas Jul 23 '14 at 17:37
  • path should be where your SDK is, for me it was /opt/android-sdk – Jadeye Nov 13 '14 at 19:26
  • Adding this file to an Eclipse ADT project root folder, fixed the issue as well - Thanks! – Gene Bo Mar 03 '15 at 23:32
  • It's already took default by IDE in my case, but still same issue. Any suggestion! – CoDe Jan 02 '16 at 07:25
  • In my case, I had just recently removed the android NDK but the ndk line in my `local.properties` file was still present and caused my build to fail. – B W Oct 12 '16 at 13:48
9

i have had the Same issue with running Android-Studio on windows XP. After the Update it kept giving me the same error of Gradle: A problem occurred evaluating root project. so what i had to do is:

1- make sure you know where your android studio directory is in my case it was C:\Documents and Settings\UserName\Local Settings\Application Data\Android\android-studio\sdk

2- open the project root directory

3- locate the local.properties file and open it in a text editor notepad did it for me

4- change the sdk.dir="add your SDK directory here without the quotations" and make sure you use double instead of one on each separator sdk.dir=C:\\\Documents and Settings\\\UserName\\\Local Settings\\\Application Data\\\Android\\\android-studio\\\sdk

5- Rebuild your project

That was the only way it worked for me

Stunner
  • 12,025
  • 12
  • 86
  • 145
Dulli
  • 391
  • 3
  • 5
  • Thanks for this step-by-step explanation. It's the same solution as the one from buddahbrot, but following your steps finally got it going. Thanks =) – Bahamut Aug 11 '13 at 15:44
  • 2
    Instead of double backslashes you can also use forward slashes. It said to be fixed here [https://android-review.googlesource.com/#/c/62585/] but it's still present in the newest version (0.2.5) – Derk-Jan Aug 17 '13 at 19:58
  • 1
    I'm a bit confused; Why are there **triple** backslashes up here and it states to use **double** backslashes? :/ – Bloke Aug 07 '14 at 11:18
7

For me the problem was that in OS X, I need set my ANDROID_HOME to a full path, such as:

export ANDROID_HOME="/Users/username/Development/android-sdk-macosx"

When using the user directory shorthand (~) Gradle seems to consider it a relative directory.

user1
  • 536
  • 5
  • 8
  • 1
    I experienced the same behavior on Ubuntu. `~/Android/Sdk` was getting expanded to `/home/hillshum/android-studio/~/Android/Sdk` or something resembling that – Hilton Shumway Apr 30 '16 at 01:44
2

//according to my android studio project folder

just go into local file and open it into notepad then include the following line according to your project sdk file

sdk.dir=C\:/Users/raj/AppData/Local/Android/android-studio/sdk //

2

As for me ANDROID_HOME didn't work. It shows error that path is not found/exists which is totally stupid. Also I tried to create local.properties with sdk.dir=D:/android/sdk - this also wont work with the same error saying this path does not exist. What helped me - a RELATIVE PATH, so when I set

sdk.dir=../../../android/sdk

it starts to work

Stan
  • 6,511
  • 8
  • 55
  • 87
1

For those who are confused by: "This file is automatically generated by Android Studio. # Do not modify this file -- YOUR CHANGES WILL BE ERASED!" when they open local.properties :

It works anyway, if the file is overridden, just change it again.

To easily find the location of your sdk, try: File -> Project Structure -> Android SDK.

Oded Breiner
  • 28,523
  • 10
  • 105
  • 71
0

I had same issue, because my office PC is 32-bit and my home PC is 64 bit. In the local.properties file, I changed

sdk.dir=C:/Program Files/Android/android-studio/sdk

to

sdk.dir=C:/Program Files (x86)/Android/android-studio1/sdk

note the x86 version of Program Files

Mobiletainment
  • 22,201
  • 9
  • 82
  • 98
Khan M
  • 1
0

Took me forever to find it but this was fixed with buddahbrot's suggestion of creating a local.properties file in the root of your project folder to include sdk.dir= followed by the path to the sdk location.

This worked fine before with just ANDROID_HOME set in Windows but in OSX, I needed to specify with sdk.dir.

0

The most likely cause is the local.properties file is incorrect.

Check in the root folder and app folder for local.properties and make sure they point to the SDK folder. Both files must point to the SDK folder for this to work.

sdk.dir=C:\Users\me\AppData\Local\Android\Sdk

Snappy Cracker
  • 1,393
  • 12
  • 14
0

This works for me to get rid of "Try Again" on the top about Gradle errors.

File >> Project Structure >> Project >> Android Gradle Plugin Version = 3.2.1 and Gradle Version 5.1.1 >> Ok >> Apply

Android Studio >> Build >> Make Project

You may get fine, but it will pop-up again for "Update Gradle" I choose "Do not remind me for this project"

Bay
  • 467
  • 7
  • 22
-1

according to my android studio project folder

just go into local file and open it into notepad then include the following line according to your project sdk file

sdk.dir=C\:/Users/raj/AppData/Local/Android/android-studio/sdk //
Shiva Saurabh
  • 1,281
  • 2
  • 25
  • 47