• Github 中文镜像
Sign inSign up
Watch966
Star102.4k
Fork61.8k
Branch: learning
Switch branches/tags
Branches
Tags
  •  
K / Flutter build 找不到 JDK 的报错解决.md
移动浏览 Clone
加载中...
到移动设备上浏览
27 lines 3.03 KB
First commit on 2 Apr 2021

    报错信息

    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':app:compileReleaseKotlin'.
    > Kotlin could not find the required JDK tools in the Java installation 'C:\Program Files\Java\jre1.8.0_281' used by Gradle. Make sure Gradle is running on a JDK, not JRE.
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 1m 17s
    Running Gradle task 'assembleRelease'...
    Running Gradle task 'assembleRelease'... Done                      78.9s
    Gradle task assembleRelease failed with exit code 1
    

    报错原因

    本来是没问题的,Windows 10 Java 自动更新后报错,开始以为是环境变量的问题,看了一下竟然本来就没有 JAVA_HOME,不知道怎么回事。后搜到这篇帖子:Flutter error Kotlin could not find the required JDK tools,里面提到可能是自动升级只更新了 JRE。

    解决办法

    两种解决办法,均亲测可用:

    方法一:更新 JDK

    控制面板 -> 程序 -> 程序和功能 里卸载当前 Java SE Development Kit 8,下载新版 JDK 重新安装一下就好了。

    方法二:不更新 JDK

    确认自己现有的 JDK 版本,比如我的 JRE 被自动更新到 jre1.8.0_281 之后,JDK 依然是 jdk1.8.0_271,打开 flutter 项目目录下的 android/gradle.properties,添加下面一行:

    org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_271