Invalid JDK configuration found, while importing a project via Gradle

Solution 1:

Deleting .gradle and .idea will likely solve the problem.

So:

  • Close the project
  • Go to the project dir and delete .gradle and .idea
  • Get back and re-open the project using the IDE

These two must be generated locally on your PC and not pulled from a remote or somewhere else (Also they should be in .gitignore).

In my case the reason was that these two folders were generated on another computer and I had opened a project with these two folders existing before.

Solution 2:

Just found the solution :

  • Create an empty Gradle project, then go to "Project Structure" and check the path to JDK (it should be valid, if it isn't you can add your own path).
  • Then build this empty project, wait and once done, close IntelliJ.
  • Relaunch it and try to import/open your Gradle project, now it should work.

Solution 3:

You don't need to create a new project to fix this. You can do it from the main window (Configure -> Project Defaults -> Project Structure):

enter image description here

Then, on SDKs, set the appropriate JDK home path:

enter image description here

If you are on a Mac, click on the button with 3 dots and select the folder /Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home.

I've found this here:

https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000266650-invalid-gradle-jdk-configuration-found