Cordova : Requirements check failed for JDK 1.8 or greater
Asked Answered
D

35

124

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 ?

Driedup answered 16/11, 2016 at 9:23 Comment(1)
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: oracle.com/technetwork/java/javase/downloads/…Tavia
D
66

Uninstall all previous JDK including 1.8 Install JDK 1.8

Driedup answered 16/11, 2016 at 10:37 Comment(9)
@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.Inroad
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)?Gilstrap
you still need to set the envionment variables so Cordova can find the path to your JDK superuser.com/questions/949560/…Gummite
@Driedup uninstalling other version is just a workaround not the solutionTunable
did the trick for me. gone to appwiz.cpl (from windows cmd) and removed java 7 and java sdk 7.Desulphurize
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.Coquille
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...Coccyx
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?Clyster
Install JDK 8 on MAC os by using "brew install openjdk@8"Fumarole
L
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.

Licentiate answered 6/9, 2017 at 9:26 Comment(10)
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?Allowed
Worked for me too on Ubuntu... I had done it for java but not javac! Now no need to uninstall Java 9 :)Finkelstein
Same remark here. Although JAVA_HOME was pointing to the right 1.8 JDK, only updating the system default satisfied Cordova.Rabassa
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 ?Meatball
Why this is a solution in ubuntu. Just like myoan said, why updating the system default satisfied cordova?Constipate
this does not work on ubuntu 18 unless you don@oysters:~/icosa$ sudo apt install openjdk-8-jdk ; sudo apt purge openjdk-11-*Hilliary
This worked for me. I kept seeing "sudo update-alternatives --config java" (not javac) and couldn't get it working.Estep
Yeah! @Finkelstein 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. :)Insulin
If you want to skip any prompt: sudo update-java-alternatives -s $(sudo update-java-alternatives -l | grep 8 | cut -d " " -f1)Freestanding
You can instal JDK on your MAC using home-brew $ brew install openjdk@8Fumarole
D
66

Uninstall all previous JDK including 1.8 Install JDK 1.8

Driedup answered 16/11, 2016 at 10:37 Comment(9)
@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.Inroad
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)?Gilstrap
you still need to set the envionment variables so Cordova can find the path to your JDK superuser.com/questions/949560/…Gummite
@Driedup uninstalling other version is just a workaround not the solutionTunable
did the trick for me. gone to appwiz.cpl (from windows cmd) and removed java 7 and java sdk 7.Desulphurize
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.Coquille
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...Coccyx
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?Clyster
Install JDK 8 on MAC os by using "brew install openjdk@8"Fumarole
C
47

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.

Cedell answered 1/2, 2018 at 12:8 Comment(3)
Remember to close the terminal/ IDE before trying to run your commands again.Joliejoliet
or you can just run $ . ~/.bashrc to export the env variables againTalipes
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)Mousse
B
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.

Begorra answered 7/1, 2018 at 19:58 Comment(1)
It's here: oracle.com/technetwork/java/javase/downloads/…Missi
R
34

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
Roselani answered 1/6, 2018 at 13:19 Comment(1)
This was the only correct answer for me. See this link for more info evothings.com/doc/build/cordova-install-linux.htmlGreatuncle
K
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.

Kilocalorie answered 25/8, 2020 at 5:48 Comment(0)
T
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.

Tunable answered 15/12, 2016 at 10:9 Comment(3)
if you are setting environment variables, you might find this useful superuser.com/questions/949560/…Gummite
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.Haynor
@supriyachauhan you can try reinstalling the complete stuff all over again. Else you may have to provide elaborate details to narrow down the problemTunable
L
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!

Lesbos answered 29/7, 2020 at 11:17 Comment(2)
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.Ingrowth
@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. #ffsDade
U
10

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!

Unbelief answered 7/1, 2020 at 15:56 Comment(0)
S
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.

Syst answered 2/5, 2017 at 14:4 Comment(0)
M
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.

Mcgruter answered 14/1, 2017 at 5:4 Comment(1)
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!Gigantes
S
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

Smithy answered 4/2, 2019 at 7:53 Comment(0)
O
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!

Outsider answered 9/9, 2018 at 3:54 Comment(0)
A
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
Ault answered 6/11, 2020 at 11:3 Comment(0)
H
4

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.
Hazardous answered 5/4, 2018 at 23:55 Comment(1)
there is a mix of addressing java ... from JAVA_HOME , PATH . cordova is using PATH which possibly points to java12/13Kush
I
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 :)

Ics answered 31/1, 2019 at 21:56 Comment(0)
P
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.

Psychosomatics answered 28/12, 2017 at 2:59 Comment(0)
S
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.

Shirty answered 28/7, 2018 at 9:5 Comment(0)
E
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.

Edroi answered 22/1, 2021 at 8:41 Comment(0)
O
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

Oxeyed answered 9/1, 2018 at 9:27 Comment(0)
L
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.

Lampkin answered 26/10, 2017 at 14:16 Comment(0)
N
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**
Nodarse answered 31/1, 2018 at 18:11 Comment(0)
G
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
Grillwork answered 13/10, 2018 at 21:29 Comment(0)
D
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

Drandell answered 18/3, 2019 at 17:11 Comment(0)
B
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.
Battleax answered 13/4, 2019 at 11:1 Comment(0)
U
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!

Upgrade answered 23/8, 2019 at 7:57 Comment(0)
P
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

Pompadour answered 25/5, 2020 at 16:59 Comment(0)
V
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
Virg answered 10/2, 2017 at 21:21 Comment(1)
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.Inexpensive
C
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
Chantalchantalle answered 7/11, 2017 at 8:25 Comment(0)
H
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.

Homologous answered 13/3, 2018 at 19:39 Comment(0)
D
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

Democratize answered 3/5, 2018 at 6:23 Comment(0)
S
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)
Solvent answered 19/7, 2021 at 12:8 Comment(0)
R
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

Reggiereggis answered 4/8, 2021 at 13:50 Comment(3)
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 MacOsZinnia
I don't know how it actually works on MacOs. Nevertheless, I added a picture to my answer, maybe it will help you.Reggiereggis
I have updated this answer, and I am able to solve the issue. Thanks.Zinnia
B
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..

Brisson answered 25/9, 2022 at 16:2 Comment(0)
P
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

Presser answered 21/11, 2022 at 9:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.