Reputation: 2773
Even though I manually configured JDK project structure file/Project structure it still shows this error FAILURE: Build failed with an exception.
`What went wrong: Execution failed for task ':sample:compileReleaseJavaWithJavac'.
Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_151 contains a valid JDK installation.`
I'm confused why it is still looking for C:\Program Files\Java\jre1.8.0_151 instead of JDK
Upvotes: 124
Views: 242323
Reputation: 5
After I've read the threads above, there are three approaches I've tried that work for me:
JAVA_HOME
and set its value to your JDK path containing the 'tools.jar' file e.g. C:\Program Files\Java\jdk1.8.0_311
.gradle.properties
file in your project and add the following line org.gradle.java.home=<your JDK path e.g. C:\\Program Files\\Java\\jdk1.8.0_311>
C:\Program Files\Java\jdk1.8.0_311\lib
Upvotes: 0
Reputation: 11
To Solve ERROR: Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_151 contains a valid JDK installation Error You Just need to add the java home JDK path in gradle.properties Just like this:
org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_144
Then try to rebuild project. Now your error must be solved.
The second solution is You just need to add tools.jar file to C:\Program Files\Java\jre1.8\lib this Path. First of all Copy tools.jar file from C:\Program Files\Java\jdk1.8.0_121\lib and then Paste into C:\Program Files\Java\jre1.8\lib Here. Now your error must be solved
Upvotes: 1
Reputation: 1
First of all you guys needs to check on your tool versions. below version may solve most of the problems.
Upvotes: 0
Reputation: 357
I had to add system environment variable JAVA_HOME and restart workspace. It solved the problem.
Upvotes: 0
Reputation: 2773
At last, here I found the solution.
I added jdk path org.gradle.java.home=C\:\\Program Files\\Java\\jdk1.8.0_144
to gradle.properties
file and did a rebuild. It works now.
Upvotes: 124
Reputation: 270
I faced the same problem when I installed the new android studio version and this solution works for me, so if you don't have JDK installed in the java folder or isn't the same version as JRE then you should install it (should JRE and JDK be in the same version, for example, both of them be in this version 1.8.0).
install it from this link => download JDK from Oracle
then copy tools.jar from (JDK folder) ==> jdk1.8.0../lib and paste it in (JRE folder) ==> jre1.8.0../lib
Upvotes: 1
Reputation: 1
I tried several of the above ways, but none worked for me, try the following; download the following java version Link download in Oracle, after downloading and installing it, add this to the gradle.properties file
org.gradle.java.home = C: \\ Program Files \\ Java \\ jdk1.8.0_301
and that's it, restart the vs code and simulate again, and it worked!
Upvotes: -1
Reputation: 4027
Goto android folder -> gradle.properties -> add your java sdk path
org.gradle.java.home=/Users/userName/Library/Java/JavaVirtualMachines/corretto-1.8.0_302/Contents/Home/jre
Upvotes: 0
Reputation: 538
In my case it was because the JAVA_HOME path could not find it.
Close all terminals and open a new one
Find a directory like this on your Mac: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
What may change is the version, but once you have it, it runs in that path: export JAVA_HOME = / Library / Java / JavaVirtualMachines / jdk1.8.0_91.jdk / Contents / Home
IN MY CASE I RUN THIS COMMAND AT THE ROOT OF THE REACT NATIVE PROJECT:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
AND IT WORKED.
Upvotes: 1
Reputation: 5109
If you can not find Tools.jar in JAVA_HOME, You can use this method. But you have to have Android Studio in your PC.
org.gradle.java.home=C:\\Program Files\\Android\\Android Studio\\jre
Place this in your project > android > gradle.properties
Upvotes: 4
Reputation: 21
Solution 1:
Go to your android folder > Gradle.properties > add your jdk path.
Clean and rebuild then it is done. // For Example Purpose Only
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home
Solution 2 At last, here I found the solution.
Add jdk path
to gradle.properties file and did a rebuild.
This will also solve your error.
Here is all Solution could not find tools.jar
Upvotes: 2
Reputation: 65
In my case, i had installed only the JRE so you could check to make sure you actually have a valid jdk. if not i advise you to uninstall whatever java is installed and download a correct jdk from here (the jdk comes with a jre so no need to download anything else) after set the environment variable and your done
Upvotes: 0
Reputation: 344
What I did was download the JDK from here, start a windows command prompt (windows+r CMD) and set the environment variable JAVA_HOME to c:\Program Files\Java\jdk-14 with:
set JAVA_HOME="c:\Program Files\Java\jdk-14"
Then run what I wanted to run. It failed afterwards, but on a different issue.
Upvotes: 1
Reputation: 191
The problem is your gradle build is not finding the JAVA_HOME path or JDK folder. So, you could declare the path in gradle.properties like org.gradle.java.home=C:\Program Files\Java\[or yours jdk folder name].
Use this guide for using gradle.properties.
Or (and I prefer this solution) include JAVA_HOME path in systmem variables and restart CMD.
Upvotes: 4
Reputation: 2010
My issue was two-fold:
Note: I am using Fedora Linux.
To resolve the first issue, I followed these instructions
To resolve the second, I merely added the following line to my ~/.bashrc
file:
export JAVA_HOME=/usr/lib/jvm/java/
I had to restart my IDE and terminals to ensure the change to the ~/.bashrc
took affect.
Upvotes: 2
Reputation: 1
you have to added jdk path org.gradle.java.home=C:\Program Files\Java\jdk1.8.0_102 to gradle.properties make sure you write your jdk version which installed in you system.
Upvotes: 0
Reputation: 5531
In Eclipse
Right click Project --> Java Build Path --> Libraries
Upvotes: 0
Reputation: 1789
My error was solved by uninstalling all java updates and java from control panel and reinstalling JDK
Upvotes: 2
Reputation: 231
What worked for me was updating Android Studio and updating JAVA_HOME and ANDROID_HOME environment variables. I believe it was caused due to the fact that I updated Java Version (through updater) but did not update jdk.
Upvotes: 0
Reputation: 169
This can occur if your path is too long as well. I solved this by moving my java install to
C:\Java\jdk1.8.0_211
Upvotes: 0
Reputation: 870
This happens when JDK and JRE have different versions installed on your system. Update the JDK with the matching version of JRE. Also verify that System variable path has bin value from same JDK version.
Upvotes: 4
Reputation:
for tools.jar is in C:\Program Files\Java\jdk1.8.0_201\lib. I changed installed jre in eclipse. Windows->Preferences->Java->installed JREs and make default jre to point to where your jdk is.
Upvotes: 0
Reputation: 3025
Please make sure both JDK and jre are on same version for example if you have JRE version 1.8.0_201 then JDK version should be 1.8.0_201 version.
Upvotes: 1
Reputation: 1115
ERROR: Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_121 contains a valid JDK installation
Copy tools.jar from C:\Program Files\Java\jdk1.8.0_121\lib
to C:\Program Files\Java\jre1.8\lib
.
It's resolved the problem now.
Upvotes: 108
Reputation: 2493
Just had this happen to me.
Apparently Java's automatic updater installed and configured a new version of the JRE for me, while leaving the old JDK intact. So even though I did have a JDK, it didn't match the currently "active" JRE, which was causing the error.
Download a matching version of the JDK to the JRE you currently have installed, (In OP's case 151) That should do the trick.
Upvotes: 39
Reputation: 1651
What I did was I uninstalled Java from my PC, and then downloaded and installed JDK again from Oracle. After this it worked perfectly. I think the problem was because the JRE and JDK update version were different from each other.
Upvotes: 2
Reputation: 3195
I had the same problem and fixed it like this:
Upvotes: 23