apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.59k stars 1.52k forks source link

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

Closed maniveltvl closed 3 years ago

maniveltvl commented 3 years ago

Issue Type

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

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 android@9.0.0
  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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

System Variables: image

Path variable: image

The error: image

maniveltvl commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Hi @breautek

Please find my Cordova version below cordova -v 8.1.0

``npm info cordova

cordova@10.0.0 | 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 erisu.dev@outlook.jp``

But I want to install android@9.0.0 to get Android API level 29. When I install android@9.0.0, 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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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:

$ npm ls execa
myproject@0.0.1 C:\somepath
+-- @angular-devkit/build-angular@0.13.9
| `-- webpack-dev-server@3.1.14
|   +-- internal-ip@3.0.1
|   | `-- default-gateway@2.7.2
|   |   `-- execa@0.10.0
|   `-- yargs@12.0.2
|     `-- os-locale@3.1.0
|       `-- execa@1.0.0
+-- @angular/compiler-cli@7.2.15
| `-- yargs@9.0.1
|   `-- os-locale@2.1.0
|     `-- execa@0.7.0
+-- @ionic/cli@6.11.11
| `-- os-name@4.0.0
|   `-- windows-release@4.0.0
|     `-- execa@4.0.3
+-- cordova-android@9.0.0
| `-- execa@4.0.3
`-- protractor@5.4.4
  `-- yargs@12.0.5
    `-- os-locale@3.1.0
      `-- execa@1.0.0

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 commented 3 years ago

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 commented 3 years ago

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

dahlseng commented 3 years ago

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

rkmaxwell commented 3 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 1 month ago

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