122

I am using Cordova 6.4.0 in Windows 7 OS, but I get this error once I tried to build the android version :

Issue description

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 ?

MadNeox
  • 2,453
  • 3
  • 15
  • 26
  • 3
    Ok. I had the same issue, but I couldn´t download the 1.8 version since it´s hide under other name. Its the 8u152. After a couple of hours I found it here: http://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase8-2177648.html?printOnly=1 – user2367101 Apr 26 '18 at 22:43

35 Answers35

81

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.

oseiskar
  • 3,282
  • 2
  • 22
  • 22
  • 2
    You made my day. I tried everything in past few days. Tnx a lot. But why only this works? Why setting variable has no effect? – my- Dec 23 '17 at 23:48
  • 2
    Worked for me too on Ubuntu... I had done it for `java` but not `javac`! Now no need to uninstall Java 9 :) – hughjdavey Feb 27 '18 at 12:18
  • Same remark here. Although `JAVA_HOME` was pointing to the right 1.8 JDK, only updating the system default satisfied Cordova. – myoan Apr 29 '18 at 14:34
  • 1
    When doing sudo update-alternatives --config javac There is only one alternative in link group javac (providing /usr/bin/javac): /usr/lib/jvm/java-11-openjdk-amd64/bin/javac Nothing to configure. i need to go back to java-8-openjdk is there away to do it ? – Taieb May 09 '18 at 13:46
  • Why this is a solution in ubuntu. Just like myoan said, why updating the system default satisfied cordova? – HexaCrop May 29 '18 at 05:30
  • this does not work on ubuntu 18 unless you don@oysters:~/icosa$ sudo apt install openjdk-8-jdk ; sudo apt purge openjdk-11-* – don bright Jun 23 '19 at 17:08
  • This worked for me. I kept seeing "sudo update-alternatives --config java" (not javac) and couldn't get it working. – crash springfield Sep 18 '20 at 20:18
  • 2
    Yeah! @hughjdavey According to source code of `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`. :) – pazfernando Nov 20 '20 at 14:09
  • If you want to skip any prompt: `sudo update-java-alternatives -s $(sudo update-java-alternatives -l | grep 8 | cut -d " " -f1)` – João Pimentel Ferreira Jul 19 '21 at 12:09
  • You can instal JDK on your MAC using home-brew $ brew install openjdk@8 – pawan vedak Jan 03 '22 at 21:14
66

Uninstall all previous JDK including 1.8 Install JDK 1.8

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
MadNeox
  • 2,453
  • 3
  • 15
  • 26
  • 3
    @Urbycoz you just need to go to `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. – Aakash Nov 30 '16 at 06:22
  • 1
    But what does it mean? How does cordova select the JDK if different JDK's are installed. It cant be possible you can only have one JDK (eg. build machine)? – Bruno Ranschaert Dec 20 '16 at 08:00
  • you still need to set the envionment variables so Cordova can find the path to your JDK http://superuser.com/questions/949560/how-do-i-set-system-environment-variables-in-windows-10#949573 – Yvonne Aburrow Jan 09 '17 at 13:52
  • 26
    @MadNeox uninstalling other version is just a workaround not the solution – Gandhi Jan 09 '17 at 17:28
  • did the trick for me. gone to appwiz.cpl (from windows cmd) and removed java 7 and java sdk 7. – Ortiz Feb 27 '18 at 18:53
  • You dont have to uninstall higher versions of java, just make sure the PATH and JAVA_HOME user variable point to your java 1.8 i.e. "C:\Program Files\Java\jdk1.8.0_181\bin" and "C:\Program Files\Java\jdk1.8.0_181" . This fixed my problem error (Requirements check failed for java1.8), hope this helps. – niq Dec 05 '18 at 06:00
  • I eventually resolved my issue by installing version 8, then running `brew install gradle` and I also reinstalled Android Studio, and now my emulator works... – Eric Milliot-Martinez Feb 19 '20 at 07:08
  • I am having the same issue, I get the error "Requirements check failed for JDK 1.8.x! Detected version: 3.0.0" when I try to build for android using cordova, quasar, and vue js. I checked java -version and I have 1.8 installed. But the error is saying it detected 3.0, which I never installed. My JAVA_HOME environment variable is set correctly. Could it be because I am using the wrong version of Gradle? – jhaubrich.com May 29 '21 at 14:14
  • Install JDK 8 on MAC os by using "brew install openjdk@8" – pawan vedak Jan 03 '22 at 21:14
46

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.

enter image description here

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

Community
  • 1
  • 1
Rashmin Javiya
  • 5,173
  • 3
  • 27
  • 49
  • 11
    Remember to close the terminal/ IDE before trying to run your commands again. – Daniel Feb 26 '18 at 20:02
  • 1
    or you can just run $ . ~/.bashrc to export the env variables again – Nick Cuevas May 13 '20 at 04:47
  • 1
    For me, this was only the first step. Also make sure the "other" JDK location is NOT mentioned in the PATH variable (either user or system) (see answer from Gandhi) – Aldinjo Apr 13 '21 at 09:20
36

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.

Esteban Morales
  • 1,626
  • 14
  • 14
32

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
Carolus
  • 477
  • 4
  • 16
Gloire
  • 1,103
  • 3
  • 17
  • 26
  • This was the only correct answer for me. See this link for more info https://evothings.com/doc/build/cordova-install-linux.html – Dara Java Oct 22 '19 at 20:19
23

MacOS answer with multiple Java versions installed and no need to uninstall

Show me what versions of Java I have installed :

$ ls -l /Library/Java/JavaVirtualMachines/

To set it to my jdk1.8 version :

$ ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/bin/javac /usr/local/bin/javac

To set it to my jdk11 version :

$ 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.

kris
  • 11,868
  • 9
  • 88
  • 110
18

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.

Gandhi
  • 11,875
  • 4
  • 39
  • 63
  • if you are setting environment variables, you might find this useful http://superuser.com/questions/949560/how-do-i-set-system-environment-variables-in-windows-10#949573 – Yvonne Aburrow Jan 09 '17 at 13:49
  • Yes i am able to run the build command with this, but still struggling with the run command 'ionic cordova run android', showing error INSTALL FAILED UPDATE INCOMPATIBLE. – supriya chauhan May 19 '18 at 19:01
  • @supriyachauhan you can try reinstalling the complete stuff all over again. Else you may have to provide elaborate details to narrow down the problem – Gandhi May 20 '18 at 06:33
14

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:

  1. Make sure JAVA_HOME and JRE_HOME is set (make sure it points to Java 1.8.*)

Env variable

  1. Inside PATH, Make sure %JAVA_HOME%\bin or C:\Program Files\Java\jdk1.8.0_251\bin is added

enter image description here

  1. Source of the problem: My JDK 11 installation added two PATH entries right at the top, taking precedence or overriding the %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

enter image description here

  1. Click "Move Down" for the overriding entries until they are below %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

enter image description here

  1. Save, and open a new terminal and run
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!

Nickson Yap
  • 1,146
  • 15
  • 23
  • 1
    I'd suggest a warning is in order: if you (others in this situation) have java 11 installed and you make this change to give java 8 priority (in the path and as the java_home), just beware that you may have something ELSE that will now break, that had been expecting to find Java 11 this way. :-) I do wish someone would document how to instead change cordova to use a specific NAMED java location, rather than rely on the system defaults, for just this situation (which MANY on the web have been hitting for years). If I find it, I hope to add a new answer to this and related SO topics. – charlie arehart Jun 04 '21 at 22:12
  • @charliearehart i am in the exact same issue apparrently cordova v11 supports JDK v11 -- lords know what has broken on our build agent. Also my build agent reports Java "1.8.0_" is installed but cordova task on DevOps says nope all i can see is v11. #ffs – IbrarMumtaz Dec 01 '22 at 20:09
9

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.

Iyke Perry
  • 341
  • 4
  • 2
9

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!

Amit Gupta
  • 2,771
  • 2
  • 17
  • 31
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.

Mawardy
  • 3,618
  • 2
  • 33
  • 37
  • Check where your Path variable is pointing to. I had JAVA_HOME pointing to 1.8 but in Path it was pointing to a different version. Worked fine after I aligned the two! – ahb Mar 04 '18 at 09:34
7

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

Shelly Pritchard
  • 10,777
  • 4
  • 18
  • 17
5

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!

MBT
  • 21,733
  • 19
  • 84
  • 102
ceeko
  • 51
  • 1
  • 1
5

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
Fernando Kosh
  • 3,426
  • 1
  • 34
  • 31
lcapra
  • 1,420
  • 16
  • 18
4

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 :)

Walterwhites
  • 1,287
  • 13
  • 9
3

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

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". enter image description here

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

Bangyno
  • 598
  • 6
  • 10
3

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.

enter image description here

  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.

enter image description here

  1. Now close terminal and reopen then run previous commands.
Boogie
  • 350
  • 3
  • 8
  • there is a mix of addressing java ... from JAVA_HOME , PATH . cordova is using PATH which possibly points to java12/13 – bortunac Feb 05 '20 at 13:34
3

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.

Tom Zych
  • 13,329
  • 9
  • 36
  • 53
Santosh
  • 31
  • 1
3

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.

Ralf
  • 293
  • 5
  • 15
2

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

Amey Bhivshet
  • 79
  • 1
  • 10
1

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.

mpm
  • 3,534
  • 23
  • 33
Aim
  • 21
  • 1
1

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**
1

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
fehrlich
  • 2,497
  • 2
  • 26
  • 44
1

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

Samson Daniel
  • 75
  • 1
  • 9
1

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.
Dominik
  • 11
  • 2
1

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!

nilsK
  • 4,323
  • 2
  • 26
  • 40
1

I'm using windows and having two jdk 1.8 and 14 version something ...

Faced same issue and after some debugging find the solution.

  1. set JAVA_HOME correctly.
  2. Change the user variable PATH value with new jdk (1.8) version.
  3. Change the user variable PATH value with new jdk (1.8) version.

And it solved

Viplav Soni
  • 1,489
  • 13
  • 18
0

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
Tom Zych
  • 13,329
  • 9
  • 36
  • 53
Livio
  • 53
  • 1
  • 3
  • On my machine the configuration of java and javac was inconsistent: java pointed to JDK 9 while javac pointed to JDK 8. Setting both to JDK 8 fixed the problem. – ominug Sep 17 '17 at 16:20
0
  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
Vojtech Ruzicka
  • 16,384
  • 15
  • 63
  • 66
Salvin
  • 1
0

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.

Dgoldenone
  • 181
  • 4
0

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

Abhay
  • 3,151
  • 1
  • 19
  • 29
0

In one line and no prompt, in Ubuntu/Debian

sudo update-java-alternatives -s $(sudo update-java-alternatives -l | grep 8 | cut -d " " -f1)
João Pimentel Ferreira
  • 14,289
  • 10
  • 80
  • 109
0

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!

Last version of JDK on top of the path

Riad Rekab
  • 109
  • 1
  • 8
  • can you please eloborate it more? I m facing this issue after setting `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 – HackRx Aug 29 '21 at 11:29
  • I don't know how it actually works on MacOs. Nevertheless, I added a picture to my answer, maybe it will help you. – Riad Rekab Aug 29 '21 at 21:49
  • I have updated [this](https://stackoverflow.com/a/48141007/11902885) answer, and I am able to solve the issue. Thanks. – HackRx Aug 30 '21 at 08:17
0

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..

Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94
0

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

Mister_CK
  • 668
  • 3
  • 13