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

时间:2016-07-20 05:51:56

标签: java android macos cordova

因此,在尝试并验证所有路径,版本和建议后,Android的cordova要求仍然失败。它是在OSX 10.10.5和Android SDKs / Studio和cordova的全新安装。尝试了Apple推荐(导出JAVA_HOME = /usr/libexec/java_home -v 1.8)并使用相同的失败结果直接路径。验证了两个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

和〜/ .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

还检查了所有符号链接:

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

在gitHub上挖掘cordova-android源代码的唯一方法是在check_reqs.js中,错误信息是:

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

而不是目前的报道:

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

任何帮助非常感谢。 罗布

2 个答案:

答案 0 :(得分:0)

所以有很多问题。 check_reqs.js是完成平台/环境检查的地方(app / platforms / android / cordova / lib /)。在第98行调用forgivingWhichSync('javac')返回非JDK链接(因为它使用的是Current,而不是CurrentJDK):     /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/javac

通过将/System/Library/Frameworks/JavaVM.framework/Versions/中的当前符号链接重新映射到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

下一个问题是测试javac的tryCommand方法存在问题。正确地说,javac -version返回stderr中的信息。问题(至少在OSX上)是第44行对child_process.exec的调用也返回错误信息:

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

如果err为非null,则处理对此child_process.exec的回调始终会触发错误:     if(err)d.reject(new CordovaError(errMsg)); 将此更改为仅在未设置catchStderr标志时才触发此错误现在可以正确处理javac的测试:     if(err&amp;&amp;!catchStderr)d.reject(new CordovaError(errMsg));

现在成功:

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 

不幸的是,当你使用cordova平台添加android时,需要为每个项目编辑check_reqs.js,但至少它现在可以找到所有内容。

答案 1 :(得分:0)

当我在OSX上使用Cordova版本7和JDK 1.8u131进行安装时,一切都运行良好。无需更改或配置任何内容。可能旧版本的Cordova存在问题。