Collectives on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more
Ask Question
* 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.
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
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.
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.
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
Open "/Library/Internet Plug-Ins", remove JavaAppletPlugin.plugin
–
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
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
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
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
–
JDK 16 doesn't have tools.jar file.
Download JDK 8, copy tools.jar file from /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/lib
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}"
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.
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.