Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-linear-gradient:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation.

When I upgraded to Mac os Big sur and run,

npx react-native run-android

I got this error (Android). I have tried a lot of solutions from Stack Overflow, but none of them worked.

I have created a fresh project and it's working. Also some of the old projects are also working perfectly.

*react-native Version: "0.63.3",*

Please help me to find a solution?

like image 640
Anandu Viswan Avatar asked Oct 06 '22 05:10

Anandu Viswan


People also ask

Can't find tools jar Please check that contains a valid JDK?

First of all Download And Install the JDK from the Oracle website with the same version number as the JRE if you didn't already. Then add JAVA_HOME to the environment variables of Windows. Restart your terminal or development environment to load the new JAVA_HOME value. Now, Your error must be solved.


4 Answers

The problem is that with the update the built-in java took precedence and it doesn't have the SDK because it's just the runtime.

You just need to change your java home and add the java binary to your .zshrc to find your java home execute:

/usr/libexec/java_home -V | grep jdk

the output should be similar to the following:

Matching Java Virtual Machines (1):
1.8.0_272 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

you should take the path from the one that says SDK in my case

/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

after that, you just add the following to the end of your .zshrc that should be in your home.

You can edit it with (if you decide to use vim you can exit writing :wq! and pressing enter)

vim .zshrc

add the following:

export JAVA_HOME=the/path/you/copied/before
export PATH=$JAVA_HOME/bin:$PATH

where the/path/you/copied/before in my case would be

/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

save the file and close all your terminals and open them again.

If while editing .zshrc file getting error ".zshrc" E212: Can't open file for writing then use sudo vim.zshrc and you'll be able to edit.

The error should be solved.

Edit

Instead of ~/.zshrc, you could have ~/.bash_profile or ~/.bash_rc so edit yours accordingly

like image 377
Cristian Gomez Avatar answered Oct 16 '22 05:10

Cristian Gomez


In my case:

I used the command /usr/libexec/java_home -V | grep jdk Cristian Gomez provided, got two paths:

Matching Java Virtual Machines (2):
    1.8.181.13 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_111 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home

Changing the .zshrc did not solve the problem.

Finally I copied tools.jar in /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/lib/ to /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/ and solved the problem.

I don't know if this approach will lead to any unknown problems.

like image 115
tomfriwel Avatar answered Oct 16 '22 06:10

tomfriwel


This worked for me -

  1. Goto android folder > gradle.properties file > add below line org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home // path to JDK

  2. Run your project again

like image 38
Yokesh Sankar Avatar answered Oct 16 '22 05:10

Yokesh Sankar


If you have something in your ~/.zshrc that resembles this:

export JAVA_HOME=$(/usr/libexec/java_home -v1.8)

just like tomfriwell wrote, you can run:

/usr/libexec/java_home -V

to see the paths of your installed JVMs and then specify which one you'd like to use. e.g:

export JAVA_HOME=$(/usr/libexec/java_home -v1.8.0_261)

and that'll link the desired JVM to your java command

don't forget to source ~/.zshrc after editing and saving

like image 8
RoyalBigMack Avatar answered Oct 16 '22 06:10

RoyalBigMack