Anandu Viswan
Anandu Viswan

Reputation: 1843

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?

Upvotes: 184

Views: 167025

Answers (24)

Dian Labuschagne
Dian Labuschagne

Reputation: 21

My problem was the that zsh and bash does not have the same path to to the jdk. So as an additional sanity check you can check what terminal you are running. Use the one the PATH was set up with.

Upvotes: 0

paakjis
paakjis

Reputation: 407

I had the same issue but it was because I installed too many JDk's. Im on MAC M1, and was not sure what jdk should I use. Newest JDK 17 was not supported by my project, I needed JDK 8 ARM. I got is from here https://www.azul.com/downloads/?version=java-8-lts&os=macos&package=jdk

But I got the same problem as OP. But it was because I had too many versions of JDK, and I have no idea where Android studio is taking the info which JDK to use.

Used /usr/libexec/java_home -V to find all the JDK's and manually deleted thema all except the ARM version.

The JDK's are installed in Macintosh HD / Library , not in Users.

Upvotes: 1

abdemirza
abdemirza

Reputation: 659

I have used every method and found out what worked for me so I have decided to compile it down for others. As told by @Heinous_Games in the comment section, install Java Uninstall Tool and it will remove Java from your system and to make sure that it works run this manually from your terminal :

sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -rf /Library/Java/JavaVirtualMachines
sudo rm -rf /Library/Application\ Support/Oracle/Java/
sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane

Go to Java Downloads page and download the file suitable for your system in my case "macOS x64 DMG Installer" and follow the instructions. I hope it works and if it doen't then restart your system once.

Upvotes: -1

Chris Gomez
Chris Gomez

Reputation: 6794

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

Upvotes: 402

Tal Spektor
Tal Spektor

Reputation: 29

Reinstall java jdk worked for me.

in Terminal:

brew tap adoptopenjdk/openjdk
brew install --cask adoptopenjdk8

Upvotes: -1

Yokesh Sankar
Yokesh Sankar

Reputation: 409

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

Upvotes: 40

Navin Kumar
Navin Kumar

Reputation: 4027

Goto android folder -> gradle.properties -> add your java sdk path like below

org.gradle.java.home=/Users/userName/Library/Java/JavaVirtualMachines/corretto-1.8.0_302/Contents/Home/jre

Upvotes: 0

Fernando Bonet
Fernando Bonet

Reputation: 606

If you are using Unity:

Open Preferences -> External Tools Under Android/JDK click on Copy Path enter image description here

then open the terminal set this as your Java home:

export JAVA_HOME="{Paste value with quotes}"

Upvotes: 0

Solvik
Solvik

Reputation: 51

Using /usr/libexec/java_home -V | grep jdk to find 2 locations then

Removing JavaAppletPlugin.plugin from "/Library/Internet Plug-Ins" worked for me.

Upvotes: 2

Kirit  Vaghela
Kirit Vaghela

Reputation: 12674

Run this command on terminal

/usr/libexec/java_home -V | grep jdk

Output

Matching Java Virtual Machines (2):
        1.8.291.10 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
        1.8.0_292 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

Copy tool.jar from

/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib

and paste to

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

Command to install JDK

brew install --cask adoptopenjdk/openjdk/adoptopenjdk8

Add following paths to .base_profile and .zshrc under Home directory

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

Upvotes: 3

Aditya Birangal
Aditya Birangal

Reputation: 122

JDK 16 doesn't have tools.jar file.

  1. Download JDK 8, copy tools.jar file from /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/lib
  2. Past it JDK 16 folder at /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/lib

Upvotes: 0

goodhyun
goodhyun

Reputation: 5002

When you have 2 Javas on your system,

    ~ % /usr/libexec/java_home -V | grep jdk
Matching Java Virtual Machines (2):
    1.8.291.10 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_144 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home

Try to add the "Java SE" path into your gradle.properties as only that package contains tools.jar

org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home

Upvotes: 4

Stich
Stich

Reputation: 2381

As I do not have ~/.zshrc on my mac these steps fixed the issue:

1)To find your java home execute:

/usr/libexec/java_home -V | grep jdk

and I see this:

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

2)To edit .bashrc I used this command:

nano ~/.bashrc

and I see the next content of my ~/.bashrc:

# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"

3)I added 2 strings at THE END of the ~/.bashrc:

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home"
export PATH="$JAVA_HOME/bin:$PATH"

where JAVA_HOME path - "/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home" is taken from STEP 1(!):

1.8.0_171 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home

Please note - paths should be inside of quotes ""

4)Close all terminal windows and build Android again.

Upvotes: 10

Rahul Singh Solanki
Rahul Singh Solanki

Reputation: 504

If you are on mac & tool.jar not found. Then first check for JAVA_HOME in your .zshrc or .bashrc.

If it is present then change the line with the below line & if it isn't present add it.

export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home 

After adding the above line run the below command.

source ~/.zshrc

or

source ~/.bashrc

Note: Make sure you have installed Android Studio already.

Upvotes: 4

codeKnightly
codeKnightly

Reputation: 652

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

run your project again react-native run-android

Original Answer: Link

Upvotes: 3

RoyalBigMack
RoyalBigMack

Reputation: 716

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

Upvotes: 9

xushao
xushao

Reputation: 93

  1. /usr/libexec/java_home -V | grep jdk

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

  1. Open "/Library/Internet Plug-Ins", remove JavaAppletPlugin.plugin

  2. OK

Upvotes: 5

Luis Izquierdo
Luis Izquierdo

Reputation: 1

Upgrade Android Studio to 4.0, and you are good to go

Upvotes: -4

Parameshwar Ande
Parameshwar Ande

Reputation: 817

Try setting JAVA HOME in android/gradle.properties file. This worked for me.

More info at https://dev.to/larrydanny/could-not-find-tools-jar-4363

Upvotes: 2

Siddharth Sogani
Siddharth Sogani

Reputation: 349

on my mac big sur SSD, Simply downloading jdk helped

Upvotes: 1

Issa Lafi
Issa Lafi

Reputation: 355

I go to java in MAC System preferences try to update java ask to remove unused version after removed finally WORKED

Upvotes: 0

Dazzle
Dazzle

Reputation: 3083

Upgrading Android Studio worked for me

Upvotes: 0

tomfriwel
tomfriwel

Reputation: 2635

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.

Upvotes: 127

daozi
daozi

Reputation: 99

This worked for me: Start Java from fresh installation.

sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -rf /Library/Java/JavaVirtualMachines
sudo rm -rf /Library/Application\ Support/Oracle/Java/
sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane

Restart computer.

Download and install Java jdk-8u271-macosx-x64

Restart computer.

Upvotes: 6

Related Questions