Cordova Failed to run "javac -version"

和其他人不一样,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是系统故障了。

你可能感兴趣的:(bug)