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 ?
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 ?
Uninstall all previous JDK including 1.8 Install JDK 1.8
Add or Remove Programs/Program Features
in Windows OS
. Next, remove any previous Java versions. I had a version 7
also installed and after uninstalling
it, cordova run android
worked. Good Luck. –
Inroad brew install gradle
and I also reinstalled Android Studio, and now my emulator works... –
Coccyx 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.
java
but not javac
! Now no need to uninstall Java 9 :) –
Finkelstein JAVA_HOME
was pointing to the right 1.8 JDK, only updating the system default satisfied Cordova. –
Rabassa check_reqs.js
the real command executed for Cordova is javac -version
so in Linux environments we have the command update-alternatives
but the mayor error is concentrate this command in java
. :) –
Insulin sudo update-java-alternatives -s $(sudo update-java-alternatives -l | grep 8 | cut -d " " -f1)
–
Freestanding Uninstall all previous JDK including 1.8 Install JDK 1.8
Add or Remove Programs/Program Features
in Windows OS
. Next, remove any previous Java versions. I had a version 7
also installed and after uninstalling
it, cordova run android
worked. Good Luck. –
Inroad brew install gradle
and I also reinstalled Android Studio, and now my emulator works... –
Coccyx 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.
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 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:
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:
$ ls -l /Library/Java/JavaVirtualMachines/
$ ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/bin/javac /usr/local/bin/javac
$ ln -s /Library/Java/JavaVirtualMachines/jdk-11.0.7.jdk/Contents/Home/bin/javac /usr/local/bin/javac
Note that, despite what the message says, it appears that it means that it wants version 1.8, and throws this message if you have a later 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 :
Set it to my jdk1.8 version
$ export PATH=/Library/Java/JavaVirtualMachines/jdk-11.0.7.jdk/Contents/Home/bin/javac:$PATH
Set it to my jdk11 version
$ export PATH=/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/bin/javac:$PATH
... but actually that doesn't work because /usr/bin/javac
is still what runs first :
$ which javac
/usr/bin/javac
... to see what runs first on the path :
$ cat /etc/paths
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
That means I can override the /usr/bin/javac
... see the commands at the top of the answer ...
The command to set it to jdk1.8 using ln
, at the top of this answer, is what worked for me.
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.
The error occurs when the default path to java is set to a version other than Java 8 or JDK 1.8.*
For my case, I have installed Java 11 after installing Java 8
You can test by running:
java -version
For my case it returned:
java version "11.0.8" 2020-07-14 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.8+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.8+10-LTS, mixed mode)
To fix this, we need to ensure the java path is pointed to Java 8 binaries instead
Assuming you already have Java 8 or JDK 1.8.* installed:
%JAVA_HOME%\bin
or C:\Program Files\Java\jdk1.8.0_251\bin
is added%JAVA_HOME%\bin
PATH that points to JDK 1.8.*Do not add these if you don't have them, find other PATH entries that may override %JAVA_HOME%\bin
%JAVA_HOME%\bin
%JAVA_HOME%\bin
PATH that points to Java 8 will now be prioritized over the other PATH entries that points to JDK 11
java -version
For my case it then returned:
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
Fixed!
Today I also got this error Cordova : Requirements check failed for JDK 1.8 or greater
in my Mac OS while build Ionic App when I run command ionic cordova build --release android
via terminal.
Below command resolve my issue :-
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home"
Hope it will help someone in future!
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.
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
I agree with @Hozington. This should be the bug on Cordova code of detecting Java version. What I did is:
JAVA_HOME
to the path of JDK 8, and change the path
variable as well.cordova build
again.And the error disappeared!
The Ubuntu/Debian Linux version of this answer is to install openjdk 8 and set the default via update-alternatives
# install (open)jdk 8
sudo apt-get install -y openjdk-8-jdk
# update java compiler and set to 1.8
sudo update-alternatives --config javac
# update java runtime (optional)
sudo update-alternatives --config java
# Also set $JAVA_HOME and $PATH to your .bashrc (optional)
echo 'export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64' >> ~/.bashrc
echo 'export PATH="$PATH:$JAVA_HOME/bin' >> ~/.bashrc
# load in current bash session
source ~/.bashrc
Guys to get the mix right on Windows, you need to do the following
C:\Program Files\Java\jdk1.8.0_162
make sure you do not add the \bin
in the value.;
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.
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 :)
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.
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.
I was running into the same problem yesterday with my new laptop (all new installation), with the only execption that for me Cordova said:
Requirements check failed for JDK 8 ('1.8.*')! Detected version: null
That Detected version: null was the actual problem for me!
When looking into the check_reqs.js (as mentioned in a post above) you will notice that this is where the magic happens: It contains a function "check_java" that, at some point, uses "execa" to retrieve the installed version of Java:
return execa('javac', ['-version'], { all: true })
.then(({ all: output }) => {
// Java <= 8 writes version info to stderr, Java >= 9 to stdout
const match = /javac\s+([\d.]+)/i.exec(output);
return match && match[1];
}
The problem for me was that, for whatever reason, I had an outdated version of "execa" which does not contain the "all" property that was used for the output. Hence, the retrieved version of Java was always undefined.
By adding "execa": "^4.0.2"
to my dependencies in the package.json and running "npm i" again I was able to fix this problem.
Just wanted to share this insight.
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
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**
if you have multiple Java versions installed and need to keep those, you need to check following things:
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
I have (Open)JDK 8 and 11 installed on Windows 10 and I had the same problem. For me the following worked:
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!
I'm using windows and having two jdk 1.8 and 14 version something ...
Faced same issue and after some debugging find the solution.
And it solved
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
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.
In one line and no prompt, in Ubuntu/Debian
sudo update-java-alternatives -s $(sudo update-java-alternatives -l | grep 8 | cut -d " " -f1)
In case any of the previous answers didn't work, I ran into the same probleme, downloading and setting the correct path on my machine. But the problem wasn't solved, until I edited the path and made %JAVA_HOME%/bin
at the begining of it (at the top of the path). And it worked perfectly fine!
export %JAVA_HOME%=
/usr/libexec/java_home` . It is giving me this error:
.zprofile:export:7: not valid in this context: %JAVA_HOME%`. I am on MacOs –
Zinnia You need to change JDK
, and not Java, 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'
More information how to set up different Java
versions: How to set or change the default Java (JDK) version on macOS?.
Then, you can use java8
, javac8
, and java11
from your terminal. In my case, it looks like this:
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.
.
Depending on your situation, you should probably upgrade Cordova android to a version >= 10.0.0. You will get this error if you are using cordova <10.0.0 with Java >8 or if you are using Cordova cordova >=10.0.0 with Java <=11. Cordova docs: https://cordova.apache.org/docs/en/latest/guide/platforms/android/#installing-the-requirements
© 2022 - 2024 — McMap. All rights reserved.