Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requirements check failed for JDK 8 ('1.8.*')! Detected version: null #1040

Closed
2 of 3 tasks
maniveltvl opened this issue Aug 7, 2020 · 23 comments
Closed
2 of 3 tasks
Labels

Comments

@maniveltvl
Copy link

maniveltvl commented Aug 7, 2020

Issue Type

Requirements check failed for JDK 8 ('1.8.*')! Detected version: null

  • Bug Report
  • Feature Request
  • Support Question

I want to upgrade my Android SDK version API Level 28 to 29. So I have added Android platform version 9.0.0. Then I try to build the APK but I am getting the below error.
'Requirements check failed for JDK 8 ('1.8.*')! Detected version: null
Check your ANDROID_SDK_ROOT / JAVA_HOME / PATH environment variables.'

Information

  1. cordova create hello com.example.hello HelloWorld
  2. cd hello
  3. cordova platform add [email protected]
  4. cordova build android

Command or Code

I found that check_req.js files line no 223 returns output as null.

Environment, Platform, Device

Platform: Android.

Version information

What are relevant versions you are using?
For example:
Cordova: 8.1.0

@breautek
Copy link
Contributor

breautek commented Aug 7, 2020

This suggests you don't have a java JDK installed. If you do, you should ensure the JAVA_HOME environment variable is pointing to the proper location.

@paulodetarsofm
Copy link

I'm facing the same problem. I have everything configured, the weird is I started to get this issue only after restart my computer, during the installation of Android Studio/SDK and creating the Cordova app for the first time, worked fine. I'm looking for a solution, no success. I reinstalled everything: Android Studio, JDK, Cordova, but nothing...

I have all these environment variables defined, but the Java version can't be detected by Cordova. If I run java -version, I get:

java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)

So, I have the Java installed! What is happening? What is the problem?

@breautek
Copy link
Contributor

breautek commented Aug 9, 2020

For linux/mac try running:

echo $JAVA_HOME

For windows i think it's:

echo %ANDROID_HOME%

But I'm not familiar with windows shell programming, so I may be recalling incorrectly.

If the shell prints out empty string/line, then you should set the JAVA_HOME environment variable.

Learn how via: https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#setting-environment-variables

@paulodetarsofm
Copy link

paulodetarsofm commented Aug 9, 2020

I'm using Windows 10. The variables are defined correctly:

System Variables:
image

Path variable:
image

The error:
image

@maniveltvl
Copy link
Author

maniveltvl commented Aug 10, 2020

Hi breautek,

I have installed JDK and i have set JAVA_HOME variable in environment variable but still it is not working. Then I have found that some issue in check_req.js.

I have changed code from
return execa('javac', ["-version"], { all: true })
to
return execa('javac -version', [], { all: true }) in line no 223

After changed to the above code able to get java version and working fine.

Can you please change to the above working code in check_req.js and commit.

@breautek breautek added the bug label Aug 10, 2020
@breautek
Copy link
Contributor

breautek commented Aug 10, 2020

Master currently has https://github.com/apache/cordova-android/blob/master/bin/templates/cordova/lib/check_reqs.js#L211 and so does v9.0.0 release: https://github.com/apache/cordova-android/blob/rel/9.0.0/bin/templates/cordova/lib/check_reqs.js

Are you sure you're up to date?

Try using cordova@10, the current latest of the cli, then reinstall the android platform:

cordova platform remove android
cordova platform add android

@maniveltvl
Copy link
Author

maniveltvl commented Aug 11, 2020

Hi @breautek

Please find my Cordova version below
cordova -v 8.1.0

``npm info cordova

[email protected] | Apache-2.0 | deps: 13 | versions: 1314
Cordova command line interface tool
https://github.com/apache/cordova-cli#readme

keywords: cordova, client, cli

bin: cordova

dist
.tarball: https://registry.npmjs.org/cordova/-/cordova-10.0.0.tgz
.shasum: 8563934f5207896efb7ea517f43065a3d0a4eaf1
.integrity: sha512-00wMcj3X9ILhKtvRG2iEwO2qly4B+vgXFhH4WhVepWg2UVbD1opl1q9jSZ+j2AaI/vsBWW8e6M2M5FAHasnuWw==
.unpackedSize: 145.4 kB

dependencies:
configstore: ^5.0.1 editor: ^1.0.0 loud-rejection: ^2.2.0 update-notifier: ^4.1.0
cordova-common: ^4.0.2 execa: ^4.0.3 nopt: ^4.0.3
cordova-create: ^3.0.0 fs-extra: ^9.0.1 semver: ^7.3.2
cordova-lib: ^10.0.0 insight: ^0.10.3 systeminformation: ^4.26.10

maintainers:

dist-tags:
3.6.0-0.2.8: 3.6.0-0.2.8 nightly: 10.0.1-nightly.2020.8.11.4e1cada0
latest: 10.0.0 rc: 5.3.3

published a week ago by erisu [email protected]``

But I want to install [email protected] to get Android API level 29. When I install [email protected], i am getting the above error. So as of now i am changing the below code to work

return execa('javac -version', [], { all: true })

@breautek
Copy link
Contributor

execa('javac -version', [], { all: true })

This should only work if executing in shell mode. It doesn't follow the documentation of execa

In general we refrain from using shell modes because it's slower, not cross-platform, and easy to introduce security vulnerabilities if care is not taken.

Additionally I haven't been able to reproduce this using the latest versions of the software.

The latest versions of cordova to date are:
cordova@10
cordova-android@9

cordova 8.1.0 is an old and no longer maintained version. If you can reproduce your issue on cordova 10 / cordova-android@9, then do let me know.

@MathieuMart
Copy link

Hi everyone;

I had the same problem on my Mac; after analyzing my package-lock.json; I had a version of execa:1.0.0 ! I don't know where it comes from.

I removed my package-lock.json and the node_modules, then I did "npm i -D execa". Which will now be in 4.0.3.

That solved my problem.

@erisu
Copy link
Member

erisu commented Aug 12, 2020

@MatHackDev I think all you needed to do was remove the package-lock.json & node_modules directory and run npm i to re-checkout the new package. I don't think you need to run npm i -D execa because this would install it at the project level and most likely not be used by cordova-android build scripts.

I also usually remove the platforms and plugins directory when upgrade and run cordova prepare to rebuild them.

@MathieuMart
Copy link

Thanks for answer @erisu but "remove the package-lock.json & node_modules directory and run npm i" it's not working for me. But i will test "remove platforms and run cordova prepare."

Maybe it's related to another package that creates a conflict.

@ajberasategui
Copy link

ajberasategui commented Aug 31, 2020

I experienced the same issue. I'm using CLI v9. Even if it does not make sense to me at all, deleting package-lock and node_modules and reinstalling did the trick. 😕

EDIT: I found the reason. Doing the "force npm modules upgrade" seems to force the update of execa dependency. The version that was being used was returning undefined when Cordova executed javac -version command to obtain the current JDK version.

@orkuncaylar
Copy link

Hi everyone;

I had the same problem on my Mac; after analyzing my package-lock.json; I had a version of execa:1.0.0 ! I don't know where it comes from.

I removed my package-lock.json and the node_modules, then I did "npm i -D execa". Which will now be in 4.0.3.

That solved my problem.
thanks!!!!!

@breautek
Copy link
Contributor

I think it's time to close this issue. The problem seems to be in the execa package, which is a sub-dependency and the problem is already fixed, but depending on when you installed Cordova, you may have an old version of execa causing this problem. As many others stated, removing the node_modules and package-lock.json file to force update all modules on npm install .

@thibaudsowa
Copy link

thibaudsowa commented Oct 6, 2020

Hi, here is my contribution.

I have exactly the same problem, after hours of research I think I have more information about this.
Actually, I discovered that the problem came from execa installed by other dependencies, there is a conflict between different versions.

Here is my dependency tree for execa:

When there is different version of a library, npm create sub node_modules directory:

The version of execa in /node_modules/execa is 0.10.0
The version of execa in /node_modules/cordova-android/node_modules/execa is 4.0.3

I don't know why but when I execute cordova build android the execa used is the first one (the bad one...)
I figured out by editing both lib file with some log.

Of course I did the classic "delete node_modules + package-lock.json" with no success.
The only workaround for me is to add execa in my own dependency, but I'm not happy with that because I don't use it and I'm afraid to delete it some day when I will do some dependency cleaning...)

Thanks for your help!

I'm on windows 10, cordova 10.0.0, cordova-android 9.0.0, npm 6.14.5, node 10.18.1

@breautek
Copy link
Contributor

breautek commented Oct 6, 2020

I don't know why but when I execute cordova build android the execa used is the first one (the bad one...)
I figured out by editing both lib file with some log.

I think you should open a new issue and fill out the issue form documenting how cordova-android appears to be using the wrong execa. I also have a theory that you can add...

That theory is because our executing code that depends on execa doesn't actually live inside node_modules/cordova-android and is instead copied into your project folder (platforms/android/). So this causes the NPM/Node module resolution to break. Consequentially, it also causes the problem to be fixed if you add it as your own dependency.

@premktr007
Copy link

try downgrading the android version. it worked for I also faced the same problem

@dahlseng
Copy link

dahlseng commented Mar 5, 2021

I Deleted J 15 in library and started build and it started :)

@rkmaxwell
Copy link

rkmaxwell commented Mar 24, 2021

Okay so this is how i solved it: I am using jdk 1.8u 261, so i therefore uninstalled any other version below this version, close the CLI and reopen then run -cordova build android if you added android platform or cordova build ios for ios.

image

@fbl773
Copy link

fbl773 commented May 27, 2021

I had an issue similar to this, my version check failed because I am running with JDK 15.0.
I saw where the error was coming from so I modified the file at platforms/android/cordova/lib/check_reqs.js to have
EXPECTED_JAVA_VERSION = "15.x" rather than 1.8.x and everything ran fine... Why is it still dependent on JDK 1.8? Should this not have worked?

@breautek
Copy link
Contributor

breautek commented May 27, 2021

EXPECTED_JAVA_VERSION = "15.x" rather than 1.8.x and everything ran fine... Why is it still dependent on JDK 1.8? Should this not have worked?

Android SDK & Android Gradle Plugin only officially supports Java 7 and 8. Last time I tested on anything higher, you could build but not all of the android tooling works on Java > 8. I think it was the sdkmanager specifically that didn't play ball on Java > 8 if memory serves me correctly.

Android will be officially supporting Java 11 soon (not sure when it will be released but Java11 support is available in their prerelease)

@lihas
Copy link

lihas commented Jun 16, 2021

In my case I had "C:\Program Files\Common Files\Oracle\Java\javapath" in system path before the path to the jdk I wanted cordova to see -C:\Program Files\Java\jdk1.8.0_291\bin
Switched the order and this error went away.

@iAbran
Copy link

iAbran commented Apr 5, 2024

Master currently has https://github.com/apache/cordova-android/blob/master/bin/templates/cordova/lib/check_reqs.js#L211 and so does v9.0.0 release: https://github.com/apache/cordova-android/blob/rel/9.0.0/bin/templates/cordova/lib/check_reqs.js

Are you sure you're up to date?

Try using cordova@10, the current latest of the cli, then reinstall the android platform:

cordova platform remove android
cordova platform add android

Thanks so much, unistall and install work for me. Love you bro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests