Gradle doesn't run because it can't find tools.jar in JRE

Today, when I was uploading new version of EasyFlipView library on jCenter, then I found this strange error which was not rebuilding my whole library module. The error was



Execution failed for task ':app:compileDebugJavaWithJavac'.
    Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_121 contains a valid JDK installation.

I tried googling around and found answers on StackOverflow like this and this. I tried different solutions. Here’s the one which was very simple and worked for me in an instant.

Solution

Add this to gradle.properties:

org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_91

Don’t forget to use double back slashes. For example: org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_144\ .


If you liked this article, you can read my new articles below:


profile card
Wajahat Karim
🌍 Making the world a better place, one app at a time.
🔥 Google Developer Expert (GDE) in Android . 📱 Professional Android Developer with ~10 years experience. 💻 Creator of various Open Source libraries on Android . 📝 Author of two technical books and 100+ articles on Android. 🎤 A passionate Public Speaker giving talks all over the world.
Author's picture

Wajahat Karim

🔥 Google Dev Expert (GDE) in Android .
📱 Android Dev. 💻 Open Source Contributor . 📝 Technical Writer . 🎤 Public Speaker

Senior Android Developer

Karachi, Pakistan