问题
I am using Cordova 6.4.0 in Windows 7 OS, but I get this error once I tried to build the android version :
The Java Home variable is setted correctly to the JDK path, but I don\'t know why I am getting this issue. Any suggestions please ?
回答1:
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
回答2:
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.
回答3:
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.
回答4:
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.
回答5:
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.
回答6:
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/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.
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
回答7:
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.
回答8:
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.
回答9:
I agree with @Hozington. This should be the bug on Cordova code of detecting Java version. What I did is:
- Keep the JDK 10
- Install the JDK 8
- Change the
JAVA_HOMEto the path of JDK 8, and change thepathvariable as well. - restart the "cmd" and run
cordova buildagain.
And the error disappeared!
回答10:
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
回答11:
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.
回答12:
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
回答13:
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.
回答14:
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 :)
回答15:
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.
回答16:
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**
回答17:
Guys to get the mix right on Windows, you need to do the following
- Download and install any version of JDK 1.8 or higher.
- Open environment variables, create an environment variable called JAVA_HOME and set value to JDK install path.
C:\Program Files\Java\jdk1.8.0_162make sure you do not add the\binin the value.
- In your system path variable, put a semi-colon
;and add this value to system path e.gC:\Program Files\Java\jdk1.8.0_162\bin;Here the\binis 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.
- Now close terminal and reopen then run previous commands.
回答18:
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
回答19:
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
回答20:
It's an old question, but since i just had the same problem, but the error had another source, here a short answer.
Problem accured on Windows (only) and with the Webstorm IDE 2019.2
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.
In my case (yeah it's old, it's an old cordova project ... )
executing java -version in Windows cmd.exe:
$ java -version
java version "1.8.0_221"
but executing java -version in Webstorms terminal:
$ 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.
Now Webstorm uses the os %JAVA_HOME% variable as it should and the java -version output is identical in both cases.
Hope it helps someone!
回答21:
- Go to Control panel Home
- Advanced System Settings
- Environment Variables
- Choose JAVA_HOME
- edit
- variable value for the 1.8 one
回答22:
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.
回答23:
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
回答24:
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
回答25:
I un-installed all Java installations and re-installed jdk-8u181-windows-x64. It's worked for me to avoid this issue.
回答26:
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)
回答27:
I have (Open)JDK 8 and 11 installed on Windows 10 and I had the same problem. For me the following worked:
- Set JAVA_HOME to point to JDK 8. (Mentioned in many answers before.) AND
- 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.
回答28:
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.
回答29:
Facing the same problem, I realised I hadn't change everything Java in my PC by just deleting the old JAVA_HOME dir (I had version 11 installed). I had to also edit the path variable. At least then I got the error about gradle and got over it smooth.
回答30:
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
来源:https://stackoverflow.com/questions/40628240/cordova-requirements-check-failed-for-jdk-1-8-or-greater