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?
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.
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.
Instead of ~/.zshrc
, you could have ~/.bash_profile
or ~/.bash_rc
so edit yours accordingly
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.
This worked for me -
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
Run your project again
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With