IntelliJ Gradle Plugin: 提供的 javaHome 似乎无效

类似于:
所提供的 javaHome 似乎是无效的
Android Studio 提供的 javaHome 不是有效文件夹

但是,我试图使用我的 JAVA_HOME变量是设置为 C:\Program Files\Java\jdk1.8.0_40

我不明白 intellij 为什么要在其安装目录中寻找 JDK。

情报:

Executing external task 'bootRun'...
The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.1\jre\bin\java.exe
External task execution finished 'bootRun'.

C:\>java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

C:>env
...
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_40
...
97083 次浏览

Try manually setting a JDK from File > Project Structure > Project > Project SDK, Then rebuild.

I've solved this issue by putting gradle.properties file in the same dir as build.gradle with exact path to my JDK:

org.gradle.java.home = C:/Dev/JDK

Actually it is not a correct solution, probably it should be fixed in IDE, I see in IDEA logs something like (when I executing gradle task of already imported project):

INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from C:/Dev/JDK

But when I going to import gradle module to the project I don't see such kind of message, probably IDEA passes link to bundled JRE which is actually not a JDK.

The problem lies in Intellij IDEA itself. If you go to Intellij installed directory, you will find a jre directory where it's searching for the above said java.exe. But the problem here is there is no bin directory here instead another jre directory available.So, solution is upfront. copy all the contents from inner jre directory and put it in outer jre directory.

IDEA comes in 2 versions: 32bit and 64bit.

Your JAVA_HOME is 64bit version of Java so you have to run 64bit version of the IDEA ...\IntelliJ\IntelliJ IDEA Community Edition 14.1.2\bin\idea64.exe.

Otherwise, you can provide 32bit JDK or tweak the behaviour with IDEA settings https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under

UPDATE I believe this issue has been fixed as of 14.1.3

Related bug links:

That said, I was able to get by using @Sergii Pechenizkyi's answer; however, it seems like this problem has a few different solutions.

This can be fixed by setting the Project SDK in Module settings to a JDK (as opposed to the Module SDK (which shall be Android SDK)

In my case the answers above didn't work. Here's what work for me: I needed to change Gradle JVM to point to the actual JDK: Image showing IntelliJ Settings window

Upgrading IntelliJ UE from v14.1.1 to 14.1.7 worked for me.

It is not working on the Mac as of 16.3. The SDK was set correctly in Project Settings and the Gradle dialog box no longer allows you to select the JDK. The only solution that worked was creating the gradle.properties file.

On OSX 10.12.x, Intellij v16.3, I had to go into:

  1. ~/Library/Preferences/IntelliJIdea2016.3
  2. Create a file called: idea.jdk
  3. Add the following to it: /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk (or whatever JDK you have installed

This was a fix I've had to do in v16 of Intellij found on jetbrains site. At one point I had to remove it, on the upgrade to 16.3 I had to add it back. https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under

I encountered the same problem for quite a while and no matter how many forums I looked at it just did not solve the problem.

Long story short, I found out my antivirus quarantined the java.exe file. So I advise you to open your antivirus and restore the Java.exe file then relaunch android studios.

in IntelliJ 2018.1, I ran into this problem because my project SDK was set to Kotlin instead of a JDK. So, despite having a Kotlin project, it would only build if the SDK is a JDK.

I tried this and it worked for me flawlessly. go To SETTING-->SEARCH 'Gradle'---> and choose Gradle JVM and choose the option Use JAVA_HOME C:\ProgramFiles\Java\JDK\1.8 hope this helps someone.

After trying all above solution nothing worked for me. Then i looked whether the "Use project jdk" path for java is correct. To look it under File->settings->gradle-> gradle jvm I found that jdk got updated and gradle was using old jdk version. So, solution was to update Project jdk path for java in intellij. File->project structure->Platform setting->SDK, here update your right jdk path. thus the problem got solved for me.

In my case I delete ".gradle" folder and let android studio and react native download it again then problem get solved ... Notice: I'm using windows

in my case I had to delete cached java directory from Program Files/Common Files folder. This directory had previous java executa ble cached. Deleting this folder allowed system to recognize latest java executable

Had JDK 18, installed 17, and uninstalled 18. Then the error popped up. None of the solutions above worked. The quick fix was to delete other java folders in C:\Program Files\Java. That's it!