简体   繁体   English

Cordova / Android在OSX和PATH / JAVA_HOME上找不到JDK

[英]Cordova/Android not finding JDK on OSX and PATH/JAVA_HOME correct

So cordova requirements is still failing for Android after trying and verifying all paths, versions and suggestions. 因此,在尝试并验证了所有路径,版本和建议后,cordova要求仍然无法满足Android的要求。 It's on OSX 10.10.5 and a clean install of Android SDKs/Studio and cordova. 它位于OSX 10.10.5上,并且全新安装了Android SDK / Studio和cordova。 Have tried Apple recommended (export JAVA_HOME= /usr/libexec/java_home -v 1.8 ) and direct paths with same failed result. 尝试过苹果推荐的方法(export JAVA_HOME = /usr/libexec/java_home -v 1.8 ),并以相同的失败结果定向路径。 Have verified both java/javac are in the bin directory of the JDK path. 验证两个java / javac都在JDK路径的bin目录中。

sh-3.2# cordova requirements
Requirements check results for android:
Java JDK: not installed 
Failed to run "java -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: /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home

Android SDK: installed 
Android target: installed android-9,android-10,android-19,android-22,android-23,android-24,Google Inc.:Google APIs:22,Google Inc.:Google APIs:23
Gradle: installed 
Error: Some of requirements check failed

sh-3.2# echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/dzhon/bin:/opt/dzhon/sbin:/opt/X11/bin:/usr/local/MacGPG2/bin:/Users/rob/Library/Android/sdk/tools:/Users/rob/Library/Android/sdk/platform-tools:/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/bin:/Users/rob/Documents/software/apache-ant-1.9.7/bin

sh-3.2# echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home

sh-3.2# java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

sh-3.2# javac -version
javac 1.8.0_102

sh-3.2# node -v
v5.3.0

sh-3.2# cordova -v
6.2.0

and in ~/.bash_profile: 并在〜/ .bash_profile中:

    export ANT_HOME=/Users/rob/Documents/software/apache-ant-1.9.7
    export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
    export ANDROID_HOME=/Users/rob/Library/Android/sdk
    export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:${JAVA_HOME}/bin:$ANT_HOME/bin

have also checked all the symlinks: 还检查了所有符号链接:

sh-3.2# ls -la /System/Library/Frameworks/JavaVM.framework/Versions/
total 32
drwxr-xr-x  11 root  wheel  374 20 Jul 11:54 .
drwxr-xr-x  12 root  wheel  408  6 Jan  2016 ..
lrwxr-xr-x   1 root  wheel   10 26 Mar  2015 1.4 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 26 Mar  2015 1.4.2 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 26 Mar  2015 1.5 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 26 Mar  2015 1.5.0 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 26 Mar  2015 1.6 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 26 Mar  2015 1.6.0 -> CurrentJDK
drwxr-xr-x   8 root  wheel  272  6 Jan  2016 A
lrwxr-xr-x   1 root  wheel    1 26 Mar  2015 Current -> A
lrwxr-xr-x   1 root  wheel   59 20 Jul 11:54 CurrentJDK -> /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents

The only thing in digging through the source for cordova-android on gitHub is in check_reqs.js, the error message is: 在gitHub上挖掘cordova-android的源代码的唯一方法是在check_reqs.js中,错误消息是:

Failed to run "javac -version", make sure that you have a JDK installed.

rather than as it currently reports: 而不是目前报告的那样:

Failed to run "java -version", make sure that you have a JDK installed.

Any help greatly appreciated. 任何帮助,不胜感激。 Rob

So a number of issues. 有很多问题。 check_reqs.js is where the platform/environment checks are done (app/platforms/android/cordova/lib/). check_reqs.js是完成平台/环境检查的位置(应用程序/平台/ android / cordova / lib /)。 The call to forgivingWhichSync('javac') on line 98 was returning the non-JDK link (as it was using Current, not CurrentJDK): /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/javac 在第98行上对forgivingWhichSync('javac')的调用返回了非JDK链接(因为它使用的是Current,而不是CurrentJDK):/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/javac

By repointing the Current symlink in /System/Library/Frameworks/JavaVM.framework/Versions/ to CurrentJDK it fixed this first issue: 通过将/System/Library/Frameworks/JavaVM.framework/Versions/中的Current符号链接重新指向CurrentJDK,它解决了以下第一个问题:

lrwxr-xr-x  1 root  wheel   10 21 Jul 12:03 Current -> CurrentJDK
lrwxr-xr-x  1 root  wheel   59 21 Jul 12:06 CurrentJDK -> /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents

The next issue was a problem with the tryCommand method testing javac. 下一个问题是用于测试javac的tryCommand方法的问题。 As correctly noted, javac -version returns the information in stderr. 正确指出,javac -version返回stderr中的信息。 The issue (at least on OSX) is that the call to child_process.exec on line 44 also returns information in err: 问题(至少在OSX上是这样)是,在第44行上对child_process.exec的调用还返回了err中的信息:

Error: Command failed: /bin/sh -c javac -version
javac 1.8.0_102
javac: no source files
Usage: javac <options> <source files>
where possible options include:
  -g                         Generate all debugging info
  -g:none                    Generate no debugging info
  -g:{lines,vars,source}     Generate only some debugging info
  -nowarn                    Generate no warnings
  -verbose                   Output messages about what the compiler is doing
  -deprecation               Output source locations where deprecated APIs are     used
  -classpath <path>          Specify where to find user class files
  -cp <path>                 Specify where to find user class files
  -sourcepath <path>         Specify where to find input source files
  -bootclasspath <path>      Override location of bootstrap class files
  -extdirs <dirs>            Override location of installed extensions
  -endorseddirs <dirs>       Override location of endorsed standards path
  -d <directory>             Specify where to place generated class files
  -encoding <encoding>       Specify character encoding used by source files
  -source <release>          Provide source compatibility with specified release
  -target <release>          Generate class files for specific VM version
  -version                   Version information
  -help                      Print a synopsis of standard options
  -X                         Print a synopsis of nonstandard options
  -J<flag>                   Pass <flag> directly to the runtime system

The handling of the callback to this child_process.exec always triggered an error if err was non null: if (err) d.reject(new CordovaError(errMsg)); 如果err不为null,则此child_process.exec回调的处理始终会触发错误:if(err)d.reject(new CordovaError(errMsg)); changing this to only trigger this error if the catchStderr flag was not set now correctly handles the test for javac: if (err && !catchStderr) d.reject(new CordovaError(errMsg)); 将其更改为仅在未设置catchStderr标志的情况下才触发此错误,现在可以正确处理javac的测试:if(err &&!catchStderr)d.reject(new CordovaError(errMsg));

and now success: 现在成功了:

sh-3.2# cordova requirements

Requirements check results for android:
Java JDK: installed .
Android SDK: installed 
Android target: installed android-9,android-10,android-16,android-18,android-19,android-22,android-23,android-24,Google Inc.:Google APIs:16,Google Inc.:Google APIs:18,Google Inc.:Google APIs:22,Google Inc.:Google APIs:23
Gradle: installed 

Unfortunately need to edit check_reqs.js for each project when you cordova platform add android but at least it's now finding everything. 不幸的是,当您在cordova平台上添加android时,需要为每个项目编辑check_reqs.js,但至少现在可以找到所有内容。

Everything worked perfectly when I did the installation with Cordova version 7 and JDK 1.8u131 on OSX. 当我在OSX上使用Cordova版本7和JDK 1.8u131进行安装时,一切工作正常。 Nothing had to be changed or configured. 无需更改或配置任何内容。 Possibly the older versions of Cordova had issues. 较旧的Cordova版本可能出现问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM