Uninstalling older versions of JDK would have worked. But it may be a workaround i guess. I faced the same issue and noticed that both new version of JDK and older version JDK path has been mentioned in 'path' environmental variable.
Note: The environment variables are tricky.They are supposed to be closed by a ; before opening another. That is why we put one before adding the value and one after the value to close it.
You may have a version that is greater than 8 but Cordova only supports JDK 1.8. View this link 科尔多瓦文件
I took a look at the piece of code that actually checks for the version number of your java. Look for the following: module.exports.check_java in Platform/android/cordova/lib/check _ reqs. js. on line 220. You will see a regex and comment left by the team that Java 10 will be supported in the future.
// Let's check for at least Java 8, and keep it future proof so we can support Java 10
var match = /javac ((?:1\.)(?:[8-9]\.)(?:\d+))|((?:1\.)(?:[1-9]\d+\.)(?:\d+))/i.exec(output);
我的解决办法是:
You don't have to uninstall your current version of the JRE or JDK since the installer installs each version in a specific folder.
In the version 2019.2 Webstorm had an issue, because it internally used open jdk for the %JAVA_HOME% variable instead of the (from the os) targeted java jdk.
在我的情况下(是的,它是旧的,这是一个老 Cordova 项目...)
在 Windows cmd.exe 中执行 java -version:
$ java -version
java version "1.8.0_221"
但在 Webstorms 终端执行 java -version:
$ java -version
openjdk version "11.0.3" 2019-04-16
// more output
A fix came with the patch released later (today), version 2019.2.1.
现在 Webstorm 应该使用 os% JAVA _ HOME% 变量,而且在这两种情况下 java -version输出是相同的。
What follows is my earlier attempts which lead me to the above answer, which then worked ...
You might need to do something different depending on what's installed, so maybe these notes might help :
You need to change JDK, and not 爪哇咖啡, or at least in this situation.
To get it, you can get from Oracle, but it asked me to create an account. Therefore, I got it from https://repo.huaweicloud.com/java/jdk/8u152-b16/ while looking for Java 8u152. Next, after installation, you most probably have 2 of them.
Open vim ~/.zshrc (MacBook), and then my setup is such:
export PATH=$PATH:~/Library/Android/sdk/platform-tools
export ANDROID_HOME=~/Library/Android/sdk
export PATH="$HOME/.bin:$PATH"
export PATH="~/Library/Android/sdk/platform-tools":$PATH
export JAVAC_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/
export JAVA_11_HOME=$(/usr/libexec/java_home -v11)
export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
alias javac8='export JAVA_HOME=$JAVAC_HOME'
alias java11='export JAVA_HOME=$JAVA_11_HOME'
alias java8='export JAVA_HOME=$JAVA_8_HOME'
myuser@DMB MoveUp % java -version
java version "18.0.1.1" 2022-04-22
Java(TM) SE Runtime Environment (build 18.0.1.1+2-6)
Java HotSpot(TM) 64-Bit Server VM (build 18.0.1.1+2-6, mixed mode, sharing)
myuser@DMB MoveUp % javac -version
javac 18.0.1.1
myuser@DMB MoveUp % java11
myuser@DMB MoveUp % java -version
java version "11.0.14" 2022-01-18 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.14+8-LTS-263)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.14+8-LTS-263, mixed mode)
myuser@DMB MoveUp % javac8
myuser@DMB MoveUp % javac -version
javac 1.8.0_152
javac 1.8.0_152 is what you need to have on javac -version to fix the problem. After that, I was able to proceed further with cordova emulate android on MacBook, which initially returned Requirements check failed for JDK 1.8.x! Detected version: 18.0.1. Check your ANDROID_SDK_ROOT / JAVA_HOME / PATH environment variables..