111

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
...
Community
  • 1
  • 1
Eric Francis
  • 23,039
  • 31
  • 88
  • 122

24 Answers24

215

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

Napoleon
  • 340
  • 3
  • 13
humazed
  • 74,687
  • 32
  • 99
  • 138
  • 4
    I think this is the only answer that is actually related to "intellij gradle plugin". All other answers are irrelevant. – SOFe Jan 04 '19 at 14:12
76

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

WoogieNoogie
  • 1,258
  • 1
  • 11
  • 21
Sergii Pechenizkyi
  • 22,227
  • 7
  • 60
  • 71
  • 5
    Segii was right about my issue. But IMHO the problem is in the Intellij installer. It needs to have a question that let's you select from 32 bit (Idea.exe) and 64 bit (idea64.exe) executables. Also, the installer should be able to inspect your system and determine if it is a 32 bit or 64 bit OS and select the appropriate .EXE as the default. That would ensure any shortcuts created by the installed pointed to the likely correct version. – JerryKur Nov 03 '15 at 18:59
  • After installing, my IntelliJ Idea shortcut was pointing to the 32bit exe. I updated the shortcut and that solved the problem. – Will Calderwood Dec 04 '15 at 09:05
  • Weird, 64 bit IdeaJ doesn't start up. – arviman Jan 18 '16 at 18:54
  • this doesn't answer anything, idk why it's the main answer. the one below is much better. – bharal Apr 25 '20 at 22:13
36

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

Elist
  • 5,313
  • 3
  • 35
  • 73
mushfek0001
  • 3,845
  • 1
  • 21
  • 20
34

If someone faces this error after Android Studio update to Android Studio Electric Eel | 2022.1.1 than simply follow following steps:

Go To android studio directory (Default C:\Program Files\Android\Android Studio) remove jre folder run cmd as administrator

cd C:\Program Files\Android\Android Studio mklink /D "jre" "jbr" Thanks to this link

Nicks
  • 3,188
  • 3
  • 25
  • 29
  • In my case the `jre` folder already existed. So I deleted it and then did `mklink /D "jre" "jbr"`. Note that all require Administrator permissions. – WebViewer Jan 24 '23 at 11:23
  • @WebViewer I don't understand what you did differently from Nicks. – The incredible Jan Jan 31 '23 at 14:27
  • @TheincredibleJan You're right. I only notice now that Nicks also instructs to remove the `jre` folder. BTW, this was only one of several fixes I had to do in order to revive my dev env [after upgrading from Android Studio 2021.3.1 to 2022.1.1](https://stackoverflow.com/a/75221722/2597758) – WebViewer Feb 02 '23 at 06:17
  • `cmd /c mklink /D "jre" "jbr"` on powershell after deleting jre folder. – jayesh saha Feb 08 '23 at 05:31
  • This one worked! If somebody is facing "access denied" -> run cmd.exe as admin – soulflavacrew Mar 15 '23 at 14:05
  • I've now had this problem with two consecutive android studio updates, 2022.2.1 flamingo aswell. – bingo Apr 15 '23 at 10:59
14

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)

user39950
  • 464
  • 3
  • 15
  • This was driving me up a tree! Your answer made perfect sense of it all though: Gradle had been trying to find the java.exe in the Android SDK (as if!). – JoeHz Feb 25 '16 at 07:05
  • in my case this answer solved my problem, thank you for your answer! – mergenchik Mar 15 '19 at 09:25
11

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.

Mahesh Jamdade
  • 17,235
  • 8
  • 110
  • 131
10

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

Umamad
  • 551
  • 4
  • 10
9

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.

4ndrew
  • 15,354
  • 2
  • 27
  • 29
4

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.

Pradyumna Swain
  • 1,128
  • 1
  • 12
  • 21
3

If someone faces this error after the Android Studio update to Android Studio Electric Eel | 2022.1.1 then simply follow the following steps:

  1. Go To the Android studio directory (Default C:\Program Files\Android\Android Studio) 2. Just you need to copy all content of jbr folder to jre folder.
  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 20 '23 at 23:17
2

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.

Eric Francis
  • 23,039
  • 31
  • 88
  • 122
2

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

DenverDave
  • 55
  • 7
2

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.

Haider Malik
  • 1,581
  • 1
  • 20
  • 23
2

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

2

This solution works for me

So it seems Gradle keeps its own registry. There was a file called ./gradle/daemon/7.2/registry.bin in my user directory that was caching the invalid jdk path and once I deleted it I was able to build.

  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 03 '22 at 08:49
  • This is a good clue !!! – Condemateguadua Apr 14 '23 at 17:45
1

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

1

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.

1

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.

1

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.

Akanksha gore
  • 558
  • 1
  • 8
  • 7
1

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!

0

If someone faces this error after Android Studio update to Android Studio Electric Eel | 2022.1.1 than simply follow following steps:

Go To android studio directory (Default C:\Program Files\Android\Android Studio) remove jre folder run cmd as administrator

cd C:\Program Files\Android\Android Studio

mklink /D "jre" "jbr"

  • mklink /D "jre" "jbr" what does this do? – David Jan 15 '23 at 04:06
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 16 '23 at 10:02
0

If you get this error after updating Android Studio Electric Eel the jre location changed, before there was a "jre" folder in the Android Studio folder, now its called "jbr" so you must update your system environment variables to this new path and restart Android.

David
  • 3,971
  • 1
  • 26
  • 65
0
when you update your java sdk then its happen you must change lots of config. file but make sure you always put same kind of config in every file config . In  my case i upgrade my java SDK tp 19.0.2 `


buildscript {
    ext.kotlin_version = '1.6.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {

        classpath 'com.android.tools.build:gradle:7.0.0'
        classpath 'com.google.gms:google-services:4.3.5'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

    }
}
0

Open the C:\Program Files\Android\Android Studio\jbr and copy all of the folders and files and paste to C:\Program Files\Android\Android Studio\jre

Define the JDK on Users env , in path -> C:\Program Files\Java\jdk-19\bin , define with path root in users path ,

Define JDK on System env , in system path define without \bin root , like that -> C:\Program Files\Java\jdk-19 , it will be okey

Gankplank
  • 25
  • 4