31

today I've upgrade my MacBook to macOS Big Sur version 11.0.1. Now there is a problem coming out when I tried to build the project for Android.

Execution failed for task ':CordovaLib:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation.
Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
Siti Aishah Ismail
  • 639
  • 1
  • 13
  • 31

7 Answers7

50

Try running

/usr/libexec/java_home -V

And see if this shows in the list

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

This was the case for me and I had to remove the entries to the Internet Plug-Ins folder. Check here for more details that helped me.

user3572565
  • 754
  • 7
  • 15
30

I also faced the same issue today while the same setup (building the Android app) was working for me before upgrading to Big Sur.

I saw various solutions like-

  1. Flutter could not find tools.jar
  2. Not able to run Eclipse on macOS Big Sur

But I was not sure if those were recommended solution. I tried for few hours and finally got it working with the correct fix (looks to me).

Basically, for me, the JAVA_HOME variable was not set (or Big Sur removed it somehow).

So I simply added it in my ~/.zshrc (or ~/.bashrc)-

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home

You can simply check and replace the version number in the above line.

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
25

If this is not still resolved for the Cordova android build -- just do it manually. My case: java_home is set properly and also reloaded ~/.zshrc (or ~/.bashrc) files. And I am getting JAVA_HOME value by echoing on terminal.

So I manually copied file tool.jar from /Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib to /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib And It worked.

For ease use this cmd

sudo cp /Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/tools.jar /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib

Just check your JAVA JDK version.

kunj choksi
  • 381
  • 3
  • 9
  • 1
    Typo or not? I had 1.8.0.121.jdk NOT _211. In addition I also followed this: https://explainjava.com/set-java-home-mac-os/ – Dave Nov 28 '20 at 21:01
15

The issue happens because of the environment variable JAVA_HOME is not correctly set.

Step 1 - Confirm that you have issue with JAVA_HOME by printing its value in the terminal. You will most likely get an empty string.

echo $JAVA_HOME

Step 2 - Find the correct path on your machine

/usr/libexec/java_home -V

Copy that path associated with "Java SE 8" which usually looks like /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home

Step 3 - Edit .zshenv using nano

nano ~/.zshenv

Step 4 - Add the path from step 2 to the file as follows

export JAVA_HOME=YOUR_JAVA_PATH

example:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home

Step 5 - Source the updated .zshenv file to activate the environment variable

source ~/.zshenv

Step 6 - Print to confirm the path

echo $JAVA_HOME
Future2020
  • 9,939
  • 1
  • 37
  • 51
2

After updating Mac Os to Big Sur I faced the same problem, Solution :

  • me 2. i have downloaded the latest version. for example jdk-8u291. then i ran this cmd and problem fixed. sudo cp /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/lib/tools.jar /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib – Ali Abdulaal Jun 20 '21 at 14:52
  • That really worked for me cool... thanks – Sathish Sundar Sep 22 '21 at 10:15
2

In my case the issue occurs because JAVA_HOME path updated with /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home which have many issues

While runing /usr/libexec/java_home -V on terminal found:

1.8.151.12 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_151 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home

so I changed it to use old working one

This can help to set or change the default Java (JDK)

Ahmed Wahba
  • 96
  • 1
  • 7
0

I also solved the same problem by downloading the latest version of jdk 8 and installing it. I also set my .bash_profile (it can be the one of your preference), adding the JAVA path as follows:

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-latest-version/Contents/Home"