Cordova Failed to run "javac -version"

本文记录了一次使用Cordova构建项目时遇到的Java JDK未被正确识别的问题及解决方案。作者通过检查环境变量和JAVA_HOME设置,最终发现系统层面的问题导致了Cordova无法找到已安装的JDK。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

和其他人不一样,javac是确认安装成功可以运行的。也确定环境中只有一个版本的jdk。运行后报了这个错误

D:\MyDemo\test2>cordova requirements
Android Studio project detected


Requirements check results for android:
Java JDK: not installed
Failed to run "javac -version", make sure that you have a JDK installed.
You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.
Your JAVA_HOME is invalid: C:\Java\jdk1.8.0_171


Android SDK: installed true
Android target: installed android-28,android-27,android-26,android-25,android-24
,android-23,android-21,android-20,android-19,android-18
Gradle: installed C:\Users\lx\.gradle\wrapper\dists\gradle-2.14.1-all\8bnwg5hd3w
55iofp58khbp6yv\gradle-2.14.1\bin\gradle
(node:8952) UnhandledPromiseRejectionWarning: CordovaError: Some of requirements
 check failed
    at C:\Users\lx\AppData\Roaming\npm\node_modules\cordova\src\cli.js:414:27
    at _fulfilled (C:\Users\lx\AppData\Roaming\npm\node_modules\cordova\node_mod
ules\cordova-lib\node_modules\q\q.js:787:54)
    at C:\Users\lx\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova
-lib\node_modules\q\q.js:816:30
    at Promise.promise.promiseDispatch (C:\Users\lx\AppData\Roaming\npm\node_mod
ules\cordova\node_modules\cordova-lib\node_modules\q\q.js:749:13)
    at C:\Users\lx\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova
-lib\node_modules\q\q.js:557:44
    at flush (C:\Users\lx\AppData\Roaming\npm\node_modules\cordova\node_modules\
cordova-lib\node_modules\q\q.js:108:17)
    at process._tickCallback (internal/process/next_tick.js:61:11)
(node:8952) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This
error originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch(). (rejection
 id: 1)
(node:8952) [DEP0018] DeprecationWarning: Unhandled promise rejections are depre
cated. In the future, promise rejections that are not handled will terminate the
 Node.js process with a non-zero exit code.

在stackOver上看到这么个回答

https://stackoverflow.com/questions/38473236/cordova-android-not-finding-jdk-on-osx-and-path-java-home-correct

做法是打开项目

test2\platforms\android\cordova\lib\check_reqs.js文件

修改第44行方法  function tryCommand (cmd, errMsg, catchStderr) 中的

if (err) d.reject(new CordovaError(errMsg)); 改为    if (err && !catchStderr) d.reject(new CordovaError(errMsg));

 

=========================

最后的解决办法是把系统重新装了一遍。找不到jdk是系统故障了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值