简体   繁体   中英

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?

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

In my case:

I used the command /usr/libexec/java_home -V | grep jdk /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 -

  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

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. eg:

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

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.

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.

  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

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.

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

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

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

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

在我的 mac big sur SSD 上,只需下载 jdk 就可以了

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

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

升级 Android Studio 对我有用

我在 MAC 系统首选项中转到 java 尝试更新 java 要求在删除后删除未使用的版本终于 WORKED

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

If you are using Unity:

Open Preferences -> External Tools Under Android/JDK click on Copy Path 在此处输入图像描述

then open the terminal set this as your Java home:

export JAVA_HOME="{Paste value with quotes}"

转到 android 文件夹-> gradle.properties -> 添加您的 java sdk 路径,如下所示

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

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.

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.

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?

Reinstall java jdk worked for me.

in Terminal:

brew tap adoptopenjdk/openjdk
brew install --cask adoptopenjdk8

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.

将 Android Studio 升级到 4.0,一切顺利

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM