Ellis
Ellis

Reputation: 3088

Android Studio - supplied javaHome is not a valid folder

I decided to update my JDK to Java 8, and installed to the default location of C:\Program Files\Java\jdk1.8.0 with a jre subdirectory.

I wasn't sure how Android Studio worked out the JDK location, so I decided to launch it and see. I got the following message:

Failed to complete Gradle execution.

Cause: Supplied javaHome is not a valid folder. You supplied: C:\Program Files\Java\jdk1.7.0_45

I updated my JAVA_HOME environment variable (both for system and user) to point to the new path, and tried adding it to my PATH variable as well, but every time I attempt to build in Android Studio I get the same message. The quoted path is nowhere to be found in my environment variables though, so where is it getting it from and how can I change it?

Thanks

Upvotes: 65

Views: 51907

Answers (11)

Tulleb
Tulleb

Reputation: 9186

I was encountering this issue using VS Code + Flutter. Cleaning gradle / changing the JDK through Android Studio did not fix it.

To fix it, I had to reset the Java cache by going into the Java status menu (bottom bar) by tapping Java: Ready: Java status menu

And then selecting the Clean Workspace Cache... menu: Clean Workspace Cache

Upvotes: 0

Kledson Alves
Kledson Alves

Reputation: 1

Try removing the .dart_tool, .idea, .vscode folders as well as the pubspec.lock file. Then run "flutter clean" and "flutter pub get".

Upvotes: 0

Luca
Luca

Reputation: 558

Getting this in 2021? Try to to rm -rf ~/.gradle and restart Android studio.

Upvotes: -1

Victor Ude
Victor Ude

Reputation: 433

I don't know why or how this problem occurred but this answer got me over the hump. On macOS rm -rf ~/.gradle to wipe out the cache then restart Android Studio. I tried everything else up to and including reinstalling the JDK and Android Studio. Wiping out the .gradle directory is the only thing that worked.

Upvotes: 8

android developer
android developer

Reputation: 116322

For some reason I failed using all the above answers, so what I did is to delete (actually moved, so that I could go back in case something goes wrong) the ".idea" folder from the project. Then I opened the IDE again, and it went fine.

Upvotes: -1

stuf99
stuf99

Reputation: 95

I ran into the same issue. My jdk was upgraded from a 1.8.0_172 to 1.8.0_202. And I kept getting the mentioned error although I changed to the right jdk, in the module configurations. What confused me was the fact that the API version was stamped with the old *_172 version in the dropdown of available project sdk's. I found the reason for this to be an old obsolete entry in the dropdown that referenced the old *172. After deleting this entry, the APi versions was magically stamped with the new version.

Java versions

Note to self: Remember to sanitize your projects when new versions come along

Upvotes: 3

Desik
Desik

Reputation: 635

Try to delete all .iml files and .idea, and re-import the project from Gradle. Worked for me (provided you have everything else set up).

This error happens when you switch from Intellij to Android Studio, or the other way around, and load the same project. Looks like their project model is not compatible.

Upvotes: 5

Sooth
Sooth

Reputation: 3084

I was also seeing this same problem. For me the fix was in 'Run/Debug Configurations' (Run > Edit Configurations...)

The 'Gradle project' value was set to the build.gradle file location, and this should've been set to the Gradle project object in IDEA, click the folder looking icon not the '...'.

Upvotes: 2

omJohn8372
omJohn8372

Reputation: 174

I'm in 1.0.2 and after I clicked OK, it immediately opened a dialog to allow me to specify the location for my project, no longer requiring navigation of the menus to edit the project JDK path.

Definitely strange that during install, it says the JAVA_HOME environment variable is set to a path that doesn't contain the JDK. After spending time fixing it (downloading the full 64 bit JDK), I create my first project and get the same thing. Because it's not using the environment variable that it hinges on during setup.

Odd behavior.

Upvotes: 0

Al Lelopath
Al Lelopath

Reputation: 6778

For Android Studio 1.1.0, after right-clicking on the project:
Select Open Module Settings
Select SDK Location at top left
Type text into JDK Location: box

Upvotes: 3

Ellis
Ellis

Reputation: 3088

The problem was my project's JDK location. From the Android Studio Project tool window, I right clicked on the root directory, selected 'module settings', and set the JDK location. Everything's fine now.

Upvotes: 149

Related Questions