Kotlin could not find the required JDK tools in the Java installation

前端 未结 5 1659
面向向阳花
面向向阳花 2020-12-20 11:11

When running ./gradlew clean build I get following message:

> Task :compileKotlin FAILED

FAILURE: Build failed with an exception.

* What we         


        
相关标签:
5条回答
  • 2020-12-20 11:36

    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

    0 讨论(0)
  • 2020-12-20 11:36

    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-amd64or /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

    0 讨论(0)
  • 2020-12-20 11:40
    > 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

    0 讨论(0)
  • 2020-12-20 11:54

    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.

    0 讨论(0)
  • 2020-12-20 12:00

    On windows, add this to gradle.properties, with your jdk version

    org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_102
    
    0 讨论(0)
提交回复
热议问题