Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_151 contains a valid JDK installation

JavaAndroidGradle

Java Problem Overview


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

Java Solutions


Solution 1 - Java

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.

Solution 2 - Java

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.

Solution 3 - Java

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.

Solution 4 - Java

I had the same problem and fixed it like this:

  1. Install the JDK from the Oracle website with the same version number as the JRE if you didn't already.
  2. Furthermore add JAVA_HOME to the environment variables of Windows.
  3. Restart your terminal or development environment to load the new JAVA_HOME value.

JAVE_HOME in System Environment Variables

Solution 5 - Java

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.

Solution 6 - Java

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.

enter image description here

Solution 7 - Java

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.

Solution 8 - Java

My error was solved by uninstalling all java updates and java from control panel and reinstalling JDK

Solution 9 - Java

My issue was two-fold:

  1. I had the JRE installed, but not the JDK.
  2. I did not have a JAVA_HOME environment variable set.

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.

Solution 10 - Java

Solution 1:

  1. Go to your android folder > Gradle.properties > add your jdk path.

  2. 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.

  1. Add jdk path

    to gradle.properties file and did a rebuild.
    
  2. This will also solve your error.

Here is all Solution could not find tools.jar

Solution 11 - Java

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.

Solution 12 - Java

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.

Solution 13 - Java

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

Solution 14 - Java

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.

Solution 15 - Java

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.

Solution 16 - Java

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

Solution 17 - Java

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.

Solution 18 - Java

In Eclipse

Right click Project --> Java Build Path --> Libraries

  1. Remove the JRE
  2. Click on Add Library --> JRE System Library -->Next -->Alternate JRE --> installed JRE --> Add JDK and select and Apply

Solution 19 - Java

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.

Solution 20 - Java

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

Solution 21 - Java

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

Solution 22 - Java

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

Solution 23 - Java

I had to add system environment variable JAVA_HOME and restart workspace. It solved the problem.

Solution 24 - Java

First of all you guys needs to check on your tool versions. below version may solve most of the problems.

  1. jdk - v11
  2. node - v16.13.1
  3. Gradle - v6.1.1

Solution 25 - Java

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!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionViswesvar SekarView Question on Stackoverflow
Solution 1 - JavaViswesvar SekarView Answer on Stackoverflow
Solution 2 - JavaAnup SinghView Answer on Stackoverflow
Solution 3 - JavaMarco AurélioView Answer on Stackoverflow
Solution 4 - JavaTon SnoeiView Answer on Stackoverflow
Solution 5 - Javasunny prakashView Answer on Stackoverflow
Solution 6 - JavaSampaView Answer on Stackoverflow
Solution 7 - Javaromin21View Answer on Stackoverflow
Solution 8 - JavahaidarView Answer on Stackoverflow
Solution 9 - JavascottysseusView Answer on Stackoverflow
Solution 10 - JavaBlogging MafiyaView Answer on Stackoverflow
Solution 11 - Javavishal jangidView Answer on Stackoverflow
Solution 12 - Javauser27221View Answer on Stackoverflow
Solution 13 - JavaLakpriya SenevirathnaView Answer on Stackoverflow
Solution 14 - JavaCaro PérezView Answer on Stackoverflow
Solution 15 - JavamatbView Answer on Stackoverflow
Solution 16 - Javacblanto7View Answer on Stackoverflow
Solution 17 - JavaMichael AlmpertisView Answer on Stackoverflow
Solution 18 - JavaupogView Answer on Stackoverflow
Solution 19 - JavaShah AlamView Answer on Stackoverflow
Solution 20 - Javaochieng sethView Answer on Stackoverflow
Solution 21 - JavaNavin KumarView Answer on Stackoverflow
Solution 22 - JavaAmina BekirView Answer on Stackoverflow
Solution 23 - JavaPrashant SView Answer on Stackoverflow
Solution 24 - JavaDijal TomView Answer on Stackoverflow
Solution 25 - JavaBrayan SanchezView Answer on Stackoverflow