Could not find tools.jar. Please check that C:\Pro

2020-01-30 17:51发布

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

15条回答
一夜七次
2楼-- · 2020-01-30 18:09

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.

查看更多
一纸荒年 Trace。
3楼-- · 2020-01-30 18:10

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.

查看更多
何必那么认真
4楼-- · 2020-01-30 18:10

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.

查看更多
小情绪 Triste *
5楼-- · 2020-01-30 18:12

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.

查看更多
Deceive 欺骗
6楼-- · 2020-01-30 18:16

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.

查看更多
看我几分像从前
7楼-- · 2020-01-30 18:17

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.

查看更多
登录 后发表回答