Android - 无法在 JRE 上编译 - 确保 Gradle 在 JDK 而不是 JRE 上运行 [英] Android - Can't compile on JRE - Make sure Gradle is running on a JDK, not JRE

查看:89
本文介绍了Android - 无法在 JRE 上编译 - 确保 Gradle 在 JDK 而不是 JRE 上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从命令行编译我的应用程序,而不是从 Android Studio.当我将它从 Android Studio 启动到我的设备/模拟器时,我的应用程序运行良好,但是当我尝试这样做时:

I want to compile my app from command line, and not from Android Studio. My app works perfectly when I launch it from Android Studio to my device / emulator, however when I try to do :

gradlew build

我明白了:

> Task :app:kaptGenerateStubsReleaseKotlin FAILED
Caught an exception trying to connect to Kotlin Daemon
org.gradle.api.GradleException: Kotlin could not find the required JDK tools in the Java installation 'C:\Program Files (x86)\Java\jre1.8.0_191' used by Gradle. Make sure Gradle is running on a JDK, not JRE.
        at org.jetbrains.kotlin.gradle.tasks.JarSearchingUtilKt.findToolsJar(jarSearchingUtil.kt:95)
        at org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment$toolsJar$2.invoke(GradleCompilerEnvironment.kt:23)
        at org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment$toolsJar$2.invoke(GradleCompilerEnvironment.kt:17)
        at kotlin.SynchronizedLazyImpl.getValue(Lazy.kt:131)
        ...

这是我的 JAVA_HOME 环境变量:

Here is my JAVA_HOME env var :

JAVA_HOME=C:\Program Files (x86)\Java\jre1.8.0_191

它实际上是一个 JRE(而不是 JDK),但是,当我通过我的 JDK 更改我的 env var 时:

It IS actually a JRE (and not a JDK), but, when I change my env var by my JDK as following :

JAVA_HOME=C:\Program Files\Java\jdk-11.0.1    

然后我启动:

gradlew build

然后我得到:

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine java version from '11.0.1'.

* 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

推荐答案

当您的 gradle 仅兼容较低的 JDK 版本时,它可能会抱怨您尝试使用 JDK 11 版本.

Its probably complaining about the fact you are trying to use a JDK 11 version when your gradle is only compatible up to a lesser JDK version.

简短的回答是 - 下载一个 JDK 1.8.something 版本并尝试使用它,替代的(可能是更好的长期)答案是将您的 gradle 版本升级到最新版本(即 JDK 11 兼容版本).

The short answer would be - download a JDK 1.8.something version and try with that, the alternate (and probably better long term) answer would be to upgrade your gradle version to the latest (i.e. a JDK 11 compatible version).

所以谷歌说你至少需要 Gradle 5.0 才能使用 JDK 11 :)

so google says that you need a minimum of Gradle 5.0 to use JDK 11 :)

这篇关于Android - 无法在 JRE 上编译 - 确保 Gradle 在 JDK 而不是 JRE 上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆