Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.
like image 324
siti aishah ismail Avatar asked Nov 16 '20 10:11

siti aishah ismail


5 Answers

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.

like image 125
user3572565 Avatar answered Oct 20 '22 12:10

user3572565


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.

like image 30
Shashank Agrawal Avatar answered Oct 20 '22 11:10

Shashank Agrawal


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.

like image 25
kunj choksi Avatar answered Oct 20 '22 11:10

kunj choksi


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
like image 15
Future2020 Avatar answered Oct 20 '22 11:10

Future2020


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

  • Download the latest JDK 8 from : https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
  • and Installed it
like image 2
Reda EL FILLALI Avatar answered Oct 20 '22 11:10

Reda EL FILLALI