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