Kotlin could not find the required JDK tools in the Java installation
Solution 1:
I solved a similar problem in MacOS (Big Sur). In my case I was running a React Native project and got the following error when trying to build to Android:
* What went wrong:
Execution failed for task ':bugsnag_react-native:compileDebugKotlin'.
> Kotlin could not find the required JDK tools in the Java installation '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home' used by G
radle. Make sure Gradle is running on a JDK, not JRE.
I followed this article for uninstalling the JRE on MacOS. Slightly modified to make the process reversible, here are the steps:
cd /Library/Internet\ Plug-Ins/
mv JavaAppletPlugin.plugin DELETED-JavaAppletPlugin.plugin
cd /Library/PreferencePanes/
mv JavaControlPanel.prefPane DELETED-JavaControlPanel.prefPane
When you receive Permission denied
use sudo
before commands.
I then cleared my Gradle folder. I don't know if this is necessary, but it worked for me:
rm -rf ~/.gradle
Finally, I rebuilt my project (react-native run-android
) and everything worked.
I'm not sure removing the JRE is the best solution since you may need the JRE for other things, but I have not noticed any ill effects. Also, it appears I already had a JDK installed which may not be true for all Mac users.
Since there are not any good answers on Stack Overflow that address this problem on MacOS, I figured I'd post my solution here.
Solution 2:
android studio also offers jdk. If you specify that jdk as below, it will succeed
export PATH=$PATH:/Applications/"Android Studio.app"/Contents/jre/jdk/Contents/Home/bin
export JAVA_HOME=/Applications/"Android Studio.app"/Contents/jre/jdk/Contents/Home
Solution 3:
Following MacOS update to Big Sur, I was seeing the same problem as Tom Aranda above. Upon further investigation, I came across this SO post and this led me to this radar. I wasn't happy removing the JRE as per Tom's answer and so have worked around my own install with details from the other posts.....
My previous declaration of JAVA_HOME
was in ~/.zshrc
as
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
but Big Sur appears to have updated the default JRE version to 1.8 also. So my JAVA_HOME needs to be more precise with its filtering.
% /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
1.8.251.08 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_241 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
And I now export as
export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_241`
Now this isn't ideal as it'll break the next time I update the JDK.
As per the details in the radar and the other SO post I also need to ensure that any existing exported JAVA_HOME is unset before exporting again, so my new entry in ~/.zshrc
has now become
unset JAVA_HOME;export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_241`
Upon terminal relaunch, my previously failing gradlew
commands now function as before.
To me this feels like a better solution as I've not removed any libs and I have only affected java home from my own terminal commands. It's a shame that I need to specify the precise version as this will break at some point in the future.
Solution 4:
on BIG SUR people who get this error have probably got a custom java installation. Remove it with the following
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencesPanes/JavaControlPanel.prefPane
sudo rm -fr ~/Library/Application\ Support/Oracle/Java
after that unset any custom JAVA_HOME you have and remove it from your shell and it should start working again.
Solution 5:
I got the exact same problem. I solved it by installing OpenJDK 8 JDK
. My machine is running centos
so here is my installing command
sudo yum install java-1.8.0-openjdk-devel
.
I learned from this article that there are two different Java packages, Java Runtime Environment (JRE) and Java Development Kit (JDK). JRE is for running Java programs, and JDK is for developing Java applications. I only had had JRE installed, but not JDK. After installing JDK, my build ran successfully