Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execution failed for task ':app:compileDebugJavaWithJavac'. > Could not find tools.jar

I get this error while executing

react-native run-android

I have tried copying tools.jar file to JRE installation location, reinstalled JDK and JRE, checked environment variables for path. Nothing worked.

It returned with the below exception

info Starting JS server...
info Building and installing the app on the device (cd android && gradlew.bat app:installDebug)...
Starting a Gradle Daemon, 1 stopped Daemon could not be reused, use --status for details
> Task :app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that C:\Program Files (x86)\Java\jre1.8.0_211 contains a valid JDK installation

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
like image 280
Gowshik Avatar asked May 31 '19 05:05

Gowshik


People also ask

Can not determine path to Tools jar?

The problem is with version of JDK you are using. The Intellij version 2020.2 supports only upto JDK 14. So either you have to lower the JDK version to 14 or update the IntelliJ to a newer version like 2021. Your answer could be improved with additional supporting information.


3 Answers

For MacOS, here are the steps:

  1. Get Current java version ( recommended 1.8 ):
$ java -version  
java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)
  1. CD to your Java home path
$ cd /Library/Java/JavaVirtualMachines
$ ls
total 0
drwxr-xr-x  3 root  wheel    96B 24 Out 09:24 adoptopenjdk-15-openj9.jre
drwxr-xr-x  3 root  wheel    96B 30 Dez 20:18 jdk1.8.0_271.jdk
  1. CD to the current java home shown at step 1 (" java 1.8.0_271" ):
$ cd jdk1.8.0_271.jdk/Contents/Home

Note: if you can't find 1.8.0_271.jdk after listing the files in the folder, you might find another jdk file like this adoptopenjdk-8.jdk use it.

  1. Copy the current path to clipboard:
$ pwd | pbcopy   
  1. Finally, open the gradle.properties file (here I'm using VSCode) and set the org.gradle.java.home variable:

org.gradle.java.home=<path_to_current_java_home>

Her is an working example:

enter image description here

like image 160
Natan Lotério Avatar answered Oct 25 '22 15:10

Natan Lotério


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\
like image 38
selva kumar Avatar answered Oct 25 '22 16:10

selva kumar


This is because valid jdk path could not be detected. Go to your project, open android folder > gradle.properties file > add below line:

org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home

and you are good to go ;)

like image 45
David Avatar answered Oct 25 '22 17:10

David