Ionic + Cordova Android build error - could not find tools.jar

12,764

Solution 1

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.

Solution 2

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.

Solution 3

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.

Solution 4

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

Solution 5

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)

Share:
12,764
Siti Aishah Ismail
Author by

Siti Aishah Ismail

Nothing much more, I'm just a kid.

Updated on June 14, 2022

Comments

  • Siti Aishah Ismail
    Siti Aishah Ismail almost 2 years

    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.