Ever since installing Android Studio 3.2, I haven't been able to run Java, I have tried jdk-8u181-windows-x64, jdk-10.0.2_windows-x64_bin, jdk-11_windows-x64_bin, setting PATH and reinstalling everything umpteen times, the result is the same - no "java" appears and the error message is: -
Gradle sync failed: Could not run JVM from the selected JDK.
Please ensure JDK installation is valid and compatible with the current OS (Windows 8.1 6.3, amd64).
If you are using embedded JDK, please make sure to download Android Studio bundle compatible
with the current OS. For example, for x86 systems please choose a 32 bits download option. (369 ms)
Notes: I used to be able to open the java folder but after playing with it too much, something went wrong, so, I decided to start afresh... and I am dead ever since.
Is Studio 3.2 flawed? Not compatible with Java at all? Or am I missing something? is there a older Android Studio I can test? Thanks for any help you may provide.
In my case, the following solved it:
File->Other settings->Default Project Structure...
In "JDK Location", I previously had the oracle jdk selected. To fix this issue, I instead checked "Use embedded JDK (recommended)"
Solved YES
Other Settings ---> Default Project Structure ---> Uncheck Embedded jdk ( Write Your Own jdk Location )
In my case, the following solved it:
File->Other settings->Default Project Structure...
setting the JAVA_HOME environment variable to C:\Program Files\Java\jdk1.8.0_181
my JDK Source File
Try setting your SDK location. I had the same problem with Android Studio 3.2 (but I also switched to openjdk, so that could be the source of my problem). Anyway, after pointing SDK location to the root of my JDK it worked like a charm.
To change SDK location click on the Android project Window and then press F4. In the new Window choose SDK location and set it to point to the root of your JDK.
i got mine working by setting the JAVA_HOME environment variable to C:\Program Files\Java\jdk1.8.0_181\bin my jdk folder
I have a project in IntelliJ Idea that uses jdk 8. In my system I have many jdk installed for development. Every time I create a new terminal window inside IntelliJ, the latest system jdk (jdk 10) is used and not the project one (jdk 8 in this case) and I have to switch manually. Of course I realise the error only after some build which requires jdk 8 does not work properly.
Is there a possibility to set the jdk used in IntelliJ terminal?
Check Preferences->Tools->Terminal do determine the used shell implementation.
Change the shell path or change your environment settings with the used shell to take effect e.g. for setting JAVA_HOME and PATH.
You can even use the "shell integration" flag to load a custom rc config file. Please check the IntelliJ documentation for this.
You are not able to use the configured projects JDK in a dynamic way. If you need this, please file an enhancement request to Jetbrains.
You need to change the SDK version in project structure. You can change it through IntelliJ navigation top bar, by following this path:
File > Project Structure > Project tab > Project SDK
I repost the answer of #yole from the comments. It is not possible.
For anyone else who stumbles on this question, here is how I resolved a similar issue:
Maybe this is just my company's security*, but when a JDK is installed with an .exe, something like the following path is created and added to the root of the %path% variable:
C:\Program Files\Common Files\Oracle\Java\javapath
On that path you'll find a 'java' executable for the installed version of java.
The fix was to simply uninstall that version of java, via the system settings.
* I mean that I was unable to see the 'true' path variable, may have been my company's security.
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
...
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:
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
Try manually setting a JDK from File > Project Structure > Project > Project SDK, Then rebuild.
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
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)
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.
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.
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
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.
If someone faces this error after the Android Studio update to Android Studio Electric Eel | 2022.1.1 then simply follow the following steps:
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.
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.
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
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 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
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.
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.
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.
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!
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.
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"
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.
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"
}
}
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
I am trying to run java application and I am getting following error,
Unable to find a javac compiler; com.sun.tools.javac.Main is not on
the classpath. Perhaps JAVA_HOME does not point to the JDK
I have gone through many SO questions and found solution is JAVA_HOME should be point to JDK, not JRE.
Then I have tried to print JAVA_HOME in command prompt,
I had set this JAVA_HOME from my computer->properties->env variables -> system vars as below,
I had also added new variable in eclipse using preferences as,
And finally I am still getting the same error. Whats wrong with JAVA_HOME ?
Update :
In eclipse-preferences-installed jres there is only one entry is present and which is jdk and selected,
And under project properties java build path-libraries there is JRE System Liberary [jdk1.8.0_31] is used.
Update 1 :
C:\Program Files\Java\jdk1.8.0_31 have folder named jre. Is that jre folder causing this issue ? Can I remove this folder ? Is there is any way to add only jdk liberary in project ?
Eclipse is an IDE and as such, it has (at least) two Java versions: The one which it uses itself to run (JAVA_HOME) and a JVM which it uses to run your application. The two don't need to be the same.
So to fix your problem, you need to look into Eclipse's preferences, specifically Installed JREs which gives you a list of Java VMs which Eclipse will use to run Java code from projects. My guess is that there will be several entries there and the default will be a JRE instead of a JDK.
Make sure you have a JDK in the list and then go to your project. In the project, you can select which Java VM to use under Java Build Path -> Libraries.
[EDIT]
Look closely at the last screenshot: You've configured Eclipse to use C:\Program Files\Java\jdk1.8.0_31\jre which means you've pointed it at the JRE inside of the JDK. Use C:\Program Files\Java\jdk1.8.0_31 instead (without the \jre at the end).
[EDIT 2] If you delete the jre folder, Java will stop working. Any JDK also contains a JRE. The JRE contains rt.jar with String.class and the like. The Java compiler is in tools.jar which is in the JDK.
If recreating the JRE entry in Eclipse doesn't help, you'll have to add it manually to the classpath.
You can use a variable ("Add Variable...") to make sure Eclipse updates the path when you switch to a new/different JRE. Try JAVA_HOME with the extension lib/tools.jar
In Eclipse click Run->External Tools->External Tools Configurations
Click JRE tab
Click Installed JREs... button
Click Add button (select Standard VM, where applicable)
Click Directory Button
Browse to your JDK version (not JRE) of your installed Java (eg: C:\Program Files\Java\jdk1.7.0_04)
Click Finish.
Re-run Ant script - have fun!
I faced the same issue while i was using ant from command prompt and the solution which I found is that you need to put tools.jar inside bin folder which is present inside apache ant folder.
For eg :-
D:\apache-ant-1.10.12-bin\lib
You will get tools.jar inside
C:\Program Files\Java\jdk1.8.0_211\lib
Please change the path based on your java installation path.
THIS QUESTION DOESNT HAVE AN ANSWER, THERE IS NO DAMN BACK BUTTON IN MY CASE!!!
Solution: ITS STILL NOT WORKING IN JDK8, you have to use ordinary Android SDK or Android Studio with JDK7! Thanks to Elliot Frisch's comment.
i hope thats the right metasite for that kind of stuff. i have properly installed java JRE and Java JDK. I can compila and execute java from commandline but if i try to install androi studio i get an error that JAVA_HOME doesnt point to a valid JVM installation.
are there additional things i have to install before using android studio or is the JAVA_HOME path different for android studio?
i put
C:/.../jre.x.x
C:/.../jre.x.x/bin
C:/.../jdk.x.x
C:/.../jdkx.x/bin
to my JAVA_HOME Path.
First, set your JAVA_HOME to only one folder (and it's the parent of bin)
set "JAVA_HOME=C:/.../jdk.x.x"
Add it to your path like
set "PATH=%PATH%;%JAVA_HOME%\bin"
I recommend to see these pages for more information, and always search before asking, I'm sure you can find the answer more quickly.
Android SDK installation doesn't find JDK
Setting JAVA_HOME at Android SDK
in windows just setting
JAVA_HOME environment variable to only "C:\Program Files\Java\jdkx.x.x_xx" is enough.
x x x -> relate to your JDK version.
C:\Program Files\Java\ -> depend to your java installation directory