Cordova : Requirements check failed for JDK 1.8 or greater

穿精又带淫゛_ 提交于 2019-11-26 19:48:28

I think I found the solution of the problem. I will post the answer just in case there is someone facing the same issue.

Uninstall all previous JDK including 1.8 Install JDK 1.8

What worked for was uninstalling jdk 9 and reinstalling jkd 8.x

On Mac in order to uninstall go to the terminal and follow this steps:

cd /Library/Java/JavaVirtualMachines

sudo rm -rf jdk-9.0.1.jdk

Then install the jdk 8.x by downloading the .dmg package from Oracle.

You don't have to uninstall any higher version of sdk. just install jdk1.8.0_161 or don't if it is already install.

Now just set the JAVA_HOME USER variable (not system variable) as shown in the below image.

This way you don't have to uninstall higher version and the problem get resolved.

In Linux (Debian/Ubuntu) this can be solved by selecting a Java 1.8 SDK in

sudo update-alternatives --config javac

Changing JAVA_HOME env variable directly does not seem to have any effect.

EDIT: responding to the comments: This probably has something to do with the fact that new Debian (and apparently Ubuntu) Java installations through the package manager do not use the JAVA_HOME enviroment variable to determine the location of the JRE. See this and this post for more info.

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.

Removing the older version JDK path from 'path' environmental variable did the trick for me. Hope it helps someone too.

You may have a version that is greater than 8 but Cordova only supports JDK 1.8. View this link Cordova Documentation

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 platforms/android/cordova/lib. on line 220. You will see a regex and comment left by the team that Java 10 will be supported in the future.

The existing regular expression will fail when it is run against the latest versions of java such as Java 10. That is because Java 8 or 9 are saved in the following format: 1.[8-9].** but Java 10 is saved as 10.** and the regular expression looks for a version in the format 1.[8-9].**

// 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);

My solution:

You don't have to uninstall your current version of the JRE or JDK since the installer installs each version in a specific folder.

1- Install version Java 8 Follow this link

2- Update your environment variables:

  • JAVA_HOME if you installed the JDK
  • JRE_HOME if you installed the JRE

by pointing them to the location where the JRE 8 and JDK 8 were installed.

// On my machine   
C:\Program Files\Java\jdk1.8.0_171 // JAVA_HOME
C:\Program Files\Java\jre1.8.0_171 // JRE_HOME

Open a new terminal session and run the command that was failing. It should work now.

Did not work?

Should it fail for other reasons, possible debugging process:

  • Ensure the JAVA_HOME and JRE_HOME variables are System variables.
  • Ensure they are added to your User's Path Add variables to Path

I dicovered that my path environmental variable was pointing to java 1.7 while JAVA_HOME was pointing to 1.8, so i edited the path variable to 1.8 and i was fine.

in my case JAVA_HOME was pointing to C:\Program Files (x86)\Java\jdk1.7.0_55

when i wrote where java in cmd it outputted C:\Program Files (x86)\Java\jdk1.7.0_55 along side with java.exe path,i've changed the JAVA_HOME variable from environment variables to C:\Program Files\Java\jdk1.8.0_20 & it worked, so it seems i had 2 jdk instances & cordova needs the v1.8.* one.

ceeko

I agree with @Hozington. This should be the bug on Cordova code of detecting Java version. What I did is:

  1. Keep the JDK 10
  2. Install the JDK 8
  3. Change the JAVA_HOME to the path of JDK 8, and change the path variable as well.
  4. restart the "cmd" and run cordova build again.

And the error disappeared!

MAC: Navigate to :/Library/Java/JavaVirtualMachines Make sure you are having only jdk1.8.0_201.jdk If you have many then remove other JDK

This error message make user confuse, the success screen as below.

The error message make user try to fix the build fail with JAVA_HOME config. But the real problem is not just in the JAVA_HOME.

I fix this problem with correct config in JAVA_HOME and Path in "system variable".

Hope can help to fix the problem, but not re-install JDK.

The answer posted by MadNeox is correct.I was facing a similar issue I had jdk 9 installed as well as the 1.8 version

I first tried by keeping jdk 9 and removing 1.8 it would display an error Requirements check failed

Then I tried by uninstalling jdk9 and reinstalling 1. this time it was showing failed to run javac-version

After playing around with the Environment variables for some time I finally got the solution

At this point my system only has jdk 1.8 Cordova version:7.1.0

-Open Environment Variables tab -Under user variables create a new variable PATH -give it the following value C:\Program Files\Java\jdk1.8.0_151\bin (might change depending on where you have installed your jdk)

This should solve your problem Hope it helps

Although the answer was already given it did take me some time to figure out where I was going wrong so decided to post this hoping it would save someone else's time

Santosh

Sometimes changing the path and java-home does not work. You need to add

C:\Users\[your user]\AppData\Local\Android\Sdk\platform-tools
C:\Users\[your user]\AppData\Local\Android\Sdk\tools

to the environmental variable path as well.

Aim

Just make sure that same JDK versions(i.e. 1.8 in this case) are accessible from PATH environment variable and JAVA_HOME. Example: If JAVA_HOME=C:\Program Files\Java\jdk1.8.0_152 then PATH variable should also contain above path and importantly before any (if there are any) other path of if JDK/JRE already mentioned in the PATH variable. You may choose to uninstall other versions if no other application is using different version of java.

If you have both jdk8 and jdk9 installed, you have to check wich version is

in the path and where JAVA_HOME is pointing to.

In the log you posted, I see that JAVA_HOME is leading to the JDK9.

modify your globel JAVA_HOME env var to target JDK8 or you can change JAVA_HOME in powershell before you use the cordova CLI if you want to use jdk8 only for cordova:

$env:JAVA_HOME="C:\Program Files\Java\jdk1.8.0_151"

**cordova build android**

Guys to get the mix right on Windows, you need to do the following

  1. Download and install any version of JDK 1.8 or higher.
  2. Open environment variables, create an environment variable called JAVA_HOME and set value to JDK install path. C:\Program Files\Java\jdk1.8.0_162 make sure you do not add the \bin in the value.

  1. In your system path variable, put a semi-colon ; and add this value to system path e.g C:\Program Files\Java\jdk1.8.0_162\bin; Here the \bin is added.

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.

  1. Now close terminal and reopen then run previous commands.

if you have multiple Java versions installed and need to keep those, you need to check following things:

  • JAVA_HOME pointing to your jdk1.8
  • in your PATH variable you need to check that jdk1.8\bin path is before the other jdk\bin paths

if you have many version of JDK you can run

export JAVA_HOME="/usr/local/env/java/jdk1.8.0_131.jdk/Contents/Home/"

before cordova build, to use a specific version of jdk :)

I faced the same issue with jdk1.8.0_201.It got resolved when I made JAVA_HOME=C:\Program Files\Java\jdk1.8.0_201 and added "C:\Program Files\Java\jdk1.8.0_201\bin" in path variable

Salvin
  1. Go to Control panel Home
  2. Advanced System Settings
  3. Environment Variables
  4. Choose JAVA_HOME
  5. edit
  6. variable value for the 1.8 one

It seems the Android SDK don't support Java 9. Downgrade to 8 if you dont want to go all the way back to JDK 1.8 which to me is ridiculous. JDK 8 work for me but be sure to set the JAVA_HOME environment variable to the location of your JDK installation correctly.

As per official Cordova documentation it supports only JDK 1.8 not greater till the date (April 2018). Or there might be problem with version detection script within cordova.

Cordova: Installing the requirements

Livio

I just renamed older JDK folder with _, just in case if I need it further, and it worked.

C:\Program Files (x86)\Java\_jdk1.7.0_40 
C:\Program Files (x86)\Java\_jre7

I un-installed all Java installations and re-installed jdk-8u181-windows-x64. It's worked for me to avoid this issue.

if problem persist,

check that :

  • JAVA_HOME refer to a available version for cordova
  • 'path' variable point on your jdk/bin (and the same jdk as your JAVA_HOME)

I have (Open)JDK 8 and 11 installed on Windows 10 and I had the same problem. For me the following worked:

  1. Set JAVA_HOME to point to JDK 8. (Mentioned in many answers before.) AND
  2. Remove(!) JDK 11 from the PATH as it turned out that -- although displaying the JAVA_HOME path pointing to JDK 8 -- Cordova actually accessed JDK 11 that was included in the PATH, which made the Java version check fail.

Even if I sat all path variable correctly I still got this message.

After digging a lot I figured out that my IDE (webstorm 19.x) is bundled with java 11. Reading this: https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under helped me switch the IDE back to java 8 which solved the problem for me.

For ubuntu users I have been watching answers but it took my time to gather solutions. For future reference uninstall the default sudo install by using the command

sudo rm -r /usr/lib/jvm/jdk10.0.2

replace the above jdk with your version which you installed mine was 10.0.2! Then go the oracle site and download the tar.gz from here . Then extract your file in home folder using the code below using terminal

tar zxvf jdk-8u201-linux-x64.tar.gz

Replace your Jdk but use jdk1.8 as it is needed by cordova same like the one above. Then set your environment variables using the code below

gedit ~/.bashrc

Text editor will pop up then add this exports thats it! It will work after you restart your computer

export JAVA_HOME=/home/abrsh/jdk1.8.0_201

Here on the above code abrsh is my username and jdk1.8.0_201 is the folder i extracted earlier using tar zxvf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!