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。
两种解决办法,均亲测可用:
在 控制面板 -> 程序 -> 程序和功能
里卸载当前 Java SE Development Kit 8
,下载新版 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