简体   繁体   English

使用 Cordova 的 JDK 1.8 或更高版本的 Java 11 要求检查失败

[英]Java 11 requirements check failed for JDK 1.8 or greater with Cordova

When I run ````cordova run android``` in the path of my project I get当我在我的项目路径中运行````cordova run android``` 时,我得到

Android Studio project detected
cordova-android-support-gradle-release: Android platform: V7+
cordova-android-support-gradle-release: Wrote custom version '27.+' to /path/to/platforms/android/app/build.gradle
cordova-android-support-gradle-release: Wrote custom version '27.+' to /path/to/cordova-android-support-gradle-release/norsan-cordova-android-support-gradle-release.gradle
ANDROID_HOME=/usr/lib/android-sdk
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
Requirements check failed for JDK 1.8 or greater

My version of Java我的 Java 版本

$ java --version
openjdk 11.0.5 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-0ubuntu1.119.04)
OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-0ubuntu1.119.04, mixed mode, sharing)

My version of javac我的javac版本

$ javac --version
javac 11.0.5

My version of Cordova我的科尔多瓦版本

$ cordova --version
9.0.0 (cordova-lib@9.0.1)

My version of Node我的节点版本

$ node --version
v10.15.2

My version of Nodejs我的 Nodejs 版本

$ nodejs --version
v10.15.2

My version of NPM我的 NPM 版本

$ npm --version
5.8.0

My version of Gradle我的 Gradle 版本

$ gradle -version
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/usr/share/java/groovy-all.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

------------------------------------------------------------
Gradle 4.4.1
------------------------------------------------------------

Build time:   2012-12-21 00:00:00 UTC
Revision:     none

Groovy:       2.4.16
Ant:          Apache Ant(TM) version 1.10.5 compiled on March 28 2019
JVM:          11.0.5 (Private Build 11.0.5+10-post-Ubuntu-0ubuntu1.119.04)
OS:           Linux 5.0.0-38-generic amd64

I found that android-studio --version didn't do anything but silently wait, but when I open the program through the graphical user interface I see that the version is 3.6.1.我发现android-studio --version没有做任何事情,只是默默等待,但是当我通过图形用户界面打开程序时,我看到版本是 3.6.1。

My version of androidsdk is Unknown... Not sure why.我的 androidsdk 版本未知...不知道为什么。

$ androidsdk --version
SDK_ROOT=/home/galen/snap/androidsdk/21/AndroidSDK
Picked up _JAVA_OPTIONS: -Duser.home=/home/galen/snap/androidsdk/21
Unknown version

My version of Ubuntu我的 Ubuntu 版本

$ cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=19.04
DISTRIB_CODENAME=disco
DISTRIB_DESCRIPTION="Ubuntu 19.04"
NAME="Ubuntu"
VERSION="19.04 (Disco Dingo)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 19.04"
VERSION_ID="19.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=disco
UBUNTU_CODENAME=disco

My understanding is that Java 11 comes later than JDK 1.8, so why does the requirements check fail?我的理解是 Java 11 晚于 JDK 1.8,那么为什么需求检查会失败呢? And, how do I fix this requirements check failure?而且,我该如何解决这个需求检查失败的问题?

You are correct that Java 11 is more recent than JDK 1.8 and that it should work in theory.你是对的,Java 11 比 JDK 1.8 更新,理论上它应该可以工作。

However, cordova explicitly requires JDK 1.8 still:但是, cordova仍然明确要求 JDK 1.8

Android doesn't use oracles java but their own implementation, which at the moment is like java 8. So this is an android limitation, not something cordova can fix. Android 不使用 oracles java 而是他们自己的实现,目前就像 java 8。所以这是一个 android 限制,不是cordova 可以修复的。

(cf. also issue 510 ) (参见第 510 期

Their development guide explicitly mentions JDK 1.8 as well:他们的开发指南也明确提到了 JDK 1.8

Java Development Kit (JDK) Java 开发工具包 (JDK)

Install Java Development Kit (JDK) 8.安装 Java 开发工具包 (JDK) 8.

So the fix for now would be installing JDK 1.8 (if you go for Oracle note their recently changed license terms).所以现在的修复是安装 JDK 1.8(如果你选择 Oracle,请注意他们最近更改的许可条款)。 You may watch PR 928 that attempts to ease that restriction, though.不过,您可以观看试图放宽该限制的PR 928

The problem here is that the command does not respect JAVA_HOME variable (you need to set this to Java 8 as well)这里的问题是该命令不尊重 JAVA_HOME 变量(您也需要将其设置为 Java 8)

As someone already mentioned, the bump from 8 to 11 is massive.正如有人已经提到的,从 8 到 11 的颠簸是巨大的。 Many libraries that were in Java 8 are moved out in Java 11, so while Java itself is backward compatible, the included libraries are not. Java 8 中的许多库在 Java 11 中被移出,因此虽然 Java 本身是向后兼容的,但包含的库不是。

What works for me is to set JAVA_HOME to JDK8对我有用的是将 JAVA_HOME 设置为 JDK8

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

AND I need to configure system wide java and javac settings with commands而且我需要使用命令配置系统范围的 java 和 javac 设置

sudo update-alternatives --config java
sudo update-alternatives --config javac

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM