可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Similar to:
- Intellij 14 the supplied javaHome seems to be invalid
- Android Studio - supplied javaHome is not a valid folder
However, I am trying to use my JAVA_HOME
variable which is set to C:\Program Files\Java\jdk1.8.0_40
I do not understand why intellij is looking for the JDK inside of its install directory.
In intellij:
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
...
回答1:
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
回答2:
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:
回答3:
Try manually setting a JDK from File > Project Structure > Project > Project SDK
, Then rebuild.
回答4:
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)
回答5:
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.
回答6:
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.
回答7:
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.
回答8:
UPDATE I believe this issue has been fixed as of 14.1.3
Related bug links:
- Intellij 14.1 cannot Import correctly Module with Gradle
That said, I was able to get by using @Sergii Pechenizkyi's answer; however, it seems like this problem has a few different solutions.
回答9:
On OSX 10.12.x, Intellij v16.3, I had to go into:
- ~/Library/Preferences/IntelliJIdea2016.3
- Create a file called: idea.jdk
- 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
回答10:
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.
回答11:
Upgrading IntelliJ UE from v14.1.1 to 14.1.7 worked for me.
回答12:
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.
回答13:
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.