[fix] Execution failed for task :core:compileJava - Could not find tools.jar


FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ":core:compileJava'

> Could not find tools.jar

If you get the above error when you try to build and run your Java Gradle-based project, the reason is tools.jar is not accessible.

Fix:

Open the build.gradle file of your project and make sure you have provided the property sourceCompatibility correctly.


Example for Android Studio Project:
...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
...

Note: Make sure Java JDK is installed on your device, if not get it installed.

Also make sure that JAVA_HOME is set in zshrc or bash profile file.


export JAVA_HOME=/path/to/java-jdk

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap