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

AndroidReact NativeReact Native-Android

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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

Solution 2 - Android

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.

Solution 3 - Android

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

Solution 4 - Android

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

Solution 5 - Android

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.

Solution 6 - Android

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.

Solution 7 - Android

  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

Solution 8 - Android

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.

Solution 9 - Android

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

Solution 10 - Android

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

Solution 11 - Android

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

Solution 12 - Android

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

Solution 13 - Android

on my mac big sur SSD, Simply downloading jdk helped

Solution 14 - Android

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

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

Solution 15 - Android

Upgrading Android Studio worked for me

Solution 16 - Android

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

Solution 17 - Android

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

Solution 18 - Android

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}"

Solution 19 - Android

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

Solution 20 - Android

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.

Solution 21 - Android

Reinstall java jdk worked for me.

in Terminal:

brew tap adoptopenjdk/openjdk
brew install --cask adoptopenjdk8

Solution 22 - Android

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.

Solution 23 - Android

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnandu ViswanView Question on Stackoverflow
Solution 1 - AndroidCristian GomezView Answer on Stackoverflow
Solution 2 - AndroidtomfriwelView Answer on Stackoverflow
Solution 3 - AndroidYokesh SankarView Answer on Stackoverflow
Solution 4 - AndroidRoyalBigMackView Answer on Stackoverflow
Solution 5 - AndroidStichView Answer on Stackoverflow
Solution 6 - AndroiddaoziView Answer on Stackoverflow
Solution 7 - AndroidxushaoView Answer on Stackoverflow
Solution 8 - AndroidRahulView Answer on Stackoverflow
Solution 9 - AndroidgoodhyunView Answer on Stackoverflow
Solution 10 - AndroidKirit VaghelaView Answer on Stackoverflow
Solution 11 - AndroidParameshwar AndeView Answer on Stackoverflow
Solution 12 - AndroidAshwin JView Answer on Stackoverflow
Solution 13 - AndroidSiddharth SoganiView Answer on Stackoverflow
Solution 14 - AndroidSolvikView Answer on Stackoverflow
Solution 15 - AndroidDazzleView Answer on Stackoverflow
Solution 16 - AndroidIssa LafiView Answer on Stackoverflow
Solution 17 - AndroidAditya BirangalView Answer on Stackoverflow
Solution 18 - AndroidFernando BonetView Answer on Stackoverflow
Solution 19 - AndroidNavin KumarView Answer on Stackoverflow
Solution 20 - AndroidpaakjisView Answer on Stackoverflow
Solution 21 - AndroidTal SpektorView Answer on Stackoverflow
Solution 22 - AndroidabdemirzaView Answer on Stackoverflow
Solution 23 - AndroidLuis IzquierdoView Answer on Stackoverflow