When running ./gradlew clean build
I get following message:
> Task :compileKotlin FAILED
FAILURE: Build failed with an exception.
* What we
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
From the data provided, It is sure that java
is in the environment path. But, It doesn't confirm that JAVA_HOME is set to a JDK directory. Are you sure JAVA_HOME
is not set to /usr/lib/jvm/java-8-openjdk-amd64/jre
instead of /usr/lib/jvm/java-8-openjdk-amd64
or /usr/lib/jvm/default-java
?
Because, If JAVA_HOME
is set, then gradlew will ignore java
binary in the PATH and execute $JAVA_HOME/bin/java
which in turn will be available in System.getProperty("java.home")
which is logged in this exception ( see jarSearchingUtil.Kt )
Otherwise, You can try declaring JAVA_HOME directly in the gradlew file
> Kotlin could not find the required JDK tools in the Java installation '/usr/lib/jvm/java-8-openjdk-amd64/jre' used by Gradle. Make sure Gradle is running on a JDK, not JRE.
it's set to /usr/lib/jvm/java-8-openjdk-amd64/jre
.
Should set the JAVA_HOME to /usr/lib/jvm/java-8-openjdk-amd64/
If your OS is Ubuntu, make suer to install openjdk jdk by sudo apt-get install openjdk-8-jdk
sudo apt install openjdk-8-jre-headless
will install jre, not jdk
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.
On windows, add this to gradle.properties, with your jdk version
org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_102