简体   繁体   English

Cordova Android的`create`脚本无法创建新项目 - 使用java / ant配置时出错

[英]`create` script for Cordova Android fails to create new project - errors with java/ant configuration

I'm trying to create a new Android project using Cordova/Phonegap. 我正在尝试使用Cordova / Phonegap创建一个新的Android项目。

I have downloaded cordova-2.9.0, and the ADT Bundle for Mac. 我已经下载了cordova-2.9.0和适用于Mac的ADT Bundle。

I extracted ADT to ~/Developer/Android, and added it to my PATH: 我将ADT提取到〜/ Developer / Android,并将其添加到我的PATH中:

export PATH="$HOME/Development/Android/sdk/tools:$PATH"
export PATH="$HOME/Development/Android/sdk/platform-tools:$PATH"

I then try to run the cordova create script, but it fails: 然后我尝试运行cordova create脚本,但它失败了:

→  bin  sudo ./create ~/Projects/myproject/cordova-android com.mydomain.myproject myproject
Password:

BUILD FAILED
/Users/asgeo1/Development/Android/sdk/tools/ant/build.xml:714: The following error occurred while executing this line:
/Users/asgeo1/Development/Android/sdk/tools/ant/build.xml:728: Compile failed; see the compiler error output for details.

Total time: 1 second
An unexpected error occurred: ant jar > /dev/null exited with 1
Deleting project...

Not very helpful. 不是很有帮助。 So I edit the Cordova create script so it will output some more information. 所以我编辑Cordova create脚本,以便输出更多信息。

    # COMMENTED OUT piping to /dev/null:
    #
    # compile cordova.js and cordova.jar
    pushd "$BUILD_PATH"/framework # > /dev/null
    ant jar #> /dev/null
    popd  #> /dev/null

Then I re-ran the create script: 然后我重新运行了create脚本:

→  bin  sudo ./create ~/Projects/myproject/cordova-android com.mydomain.myproject myproject
~/Downloads/cordova-2.9.0/cordova-android/framework ~/Downloads/cordova-2.9.0/cordova-android/bin
Buildfile: /Users/asgeo1/Downloads/cordova-2.9.0/cordova-android/framework/build.xml

-pre-build:

-check-env:
 [checkenv] Android SDK Tools Revision 22.0.5
 [checkenv] Installed at /Users/asgeo1/Development/Android/sdk

-setup:
     [echo] Project Name: Cordova
  [gettype] Project Type: Android Library

-build-setup:
[getbuildtools] Using latest Build Tools: 18.0.1
     [echo] Resolving Build Target for Cordova...
[gettarget] Project Target:   Android 4.3
[gettarget] API level:        18
     [echo] ----------
     [echo] Creating output directories if needed...
     [echo] ----------
     [echo] Resolving Dependencies for Cordova...
[dependency] Library dependencies:
[dependency] No Libraries
     [echo] ----------
     [echo] Building Libraries with '${build.target}'...
   [subant] No sub-builds to iterate on

-code-gen:
[mergemanifest] No changes in the AndroidManifest files.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
[renderscript] No RenderScript files to compile.
     [echo] ----------
     [echo] Handling Resources...
     [aapt] No changed resources. R.java and Manifest.java untouched.
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] Generating BuildConfig class.

-pre-compile:

-compile:
    [javac] Compiling 104 source files to /Users/asgeo1/Downloads/cordova-2.9.0/cordova-android/framework/bin/classes
    [javac] /Users/asgeo1/Downloads/cordova-2.9.0/cordova-android/framework/src/com/squareup/okhttp/Connection.java:171: method does not override a method from its superclass
    [javac]   @Override public void close() throws IOException {
    [javac]    ^

And there's another 40 errors like the one above, regarding @override . 对于@override ,还有另外40个错误,如上面的错误。

From what I can tell on Google, this is because in jdk 1.6 and above, the @override annotations changed. 从我在谷歌上可以看出,这是因为在jdk 1.6及以上版本中,@ override注释发生了变化。 (or something like that): Why is javac failing on @Override annotation (或类似的东西): 为什么javac在@Override注释上失败

OK, so I work out that the Android SDK configuration for ant is in a file called build.xml . 好的,所以我发现ant的Android SDK配置在一个名为build.xml的文件中。 Low and behold, it has some settings for Java 1.5: 很低,它有一些Java 1.5的设置:

<property name="java.target" value="1.5" />
<property name="java.source" value="1.5" />

If I change those values to 1.6 or 1.7, I get a java error when re-running the Cordova create script: 如果我将这些值更改为1.6或1.7,重新运行Cordova create脚本时会出现java错误:

-compile:
    [javac] Compiling 104 source files to /Users/asgeo1/Downloads/cordova-2.9.0/cordova-android/framework/bin/classes
    [javac] javac: invalid source release: 1.7
    [javac] Usage: javac <options> <source files>

I'm really scratching my head here. 我真的在这里摸不着头脑。 I'm not an expert on Java, so I don't get what is going on here. 我不是Java的专家,所以我不知道这里发生了什么。

Does anyone know how to run the create script for Cordova Android on OSX ? 有谁知道如何在OSX上运行Cordova Android的create脚本?

UPDATE UPDATE

After following @cartland's advice below I was able to get rid of the @Override errors. 按照@ cartland的建议,我可以摆脱@Override错误。 Still getting one last error though: 仍然得到最后一个错误:

-compile:
[javac] Compiling 104 source files to /Users/asgeo1/Downloads/cordova-2.9.0/cordova-android/framework/bin/classes
[javac] /Users/asgeo1/Downloads/cordova-2.9.0/cordova-android/framework/src/org/apache/cordova/InAppBrowser.java:523: error: cannot find symbol
[javac]                 settings.setPluginsEnabled(true);
[javac]                         ^
[javac]   symbol:   method setPluginsEnabled(boolean)
[javac]   location: variable settings of type WebSettings
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] 1 error

I'll try and work out what that is - but if anyone knows, please post an answer :) 我会尝试找出那是什么 - 但如果有人知道,请发一个答案:)

UPDATE 2 更新2

I know what the 2nd error is. 我知道第二个错误是什么。 It's mentioned here: https://developer.motorolasolutions.com/thread/3640 它在这里提到: https//developer.motorolaso​​lutions.com/thread/3640

Cordova 2.9.0 is not compatible with Android SDK 18. I need to use Cordova 3.0.0 with Android SDK 18. (or conversely downgrade the Android SDK to 17) Cordova 2.9.0与Android SDK 18不兼容。我需要将Cordova 3.0.0与Android SDK 18一起使用。(或者反过来将Android SDK降级为17)

I'm running Ubuntu 10.4 64bit; 我正在运行Ubuntu 10.4 64bit; Oracle JDK 1.7.0_25-b15; Oracle JDK 1.7.0_25-b15; Eclipse Kepler; Eclipse Kepler; Android SDK 4.3; Android SDK 4.3; PhoneGap 3.0. PhoneGap 3.0。

Had exactly the same problem as you using the CLI. 与您使用CLI完全相同的问题。 Loading the project into Eclipse worked fine (~/.cordova/lib/android/cordova/3.0.0/framework/.project). 将项目加载到Eclipse中工作正常(〜/ .cordova / lib / android / cordova / 3.0.0 / framework / .project)。 As Eclipse uses it's own internal Java compiler, I figured there was a problem with the Oracle install I was using, and there was - sort of. 由于Eclipse使用它自己的内部Java编译器,我认为我使用的Oracle安装存在问题,而且有一些问题。

It turned out that some application had installed a version of tools.jar (amongst others) from an earlier JRE into the Java ext folder. 事实证明,某些应用程序已将早期JRE中的tools.jar(以及其他版本)安装到Java ext文件夹中。 Seems strange to me that javac would load dependant jars from here prior to jars in it's own lib folder but that seems to be the precedence order. 对我来说似乎很奇怪,javac会在它自己的lib文件夹中加载来自此处的依赖jar,但这似乎是优先顺序。 Anyway, I removed all files from the ext folder and everything worked properly. 无论如何,我从ext文件夹中删除了所有文件,一切正常。

  • JDK location: /usr/lib/jvm/java-7-oracle/ JDK位置:/ usr / lib / jvm / java-7-oracle /
  • Ext location: /usr/java/packages/lib/ext/ Ext位置:/ usr / java / packages / lib / ext /

I don't have my Mac on me to check locations but try /Library/Java/Extensions or ~/Library/Java/Extensions 我没有我的Mac检查位置,但尝试/ Library / Java / Extensions或〜/ Library / Java / Extensions

I didn't need to make any other changes. 我不需要做任何其他更改。 However while experimenting, I did try setting the following properties in the project's ant.properties file. 但是在试验时,我确实尝试在项目的ant.properties文件中设置以下属性。 1.5, 1.6, 1.7 all work. 所有工作都是1.5,1.6,1.7。

  • java.target=1.5 java.target = 1.5
  • java.source=1.5 java.source = 1.5

Actually, the problem here seems to be the incompatibility between your java version and Cordova's compiled jars. 实际上,这里的问题似乎是你的java版本和Cordova编译的jar之间的不兼容性。 For a quick fix, it is better to install Java 1.5 and use it for your development. 要快速修复,最好安装Java 1.5并将其用于开发。 Don't forget to restore your changes in build.xml to 1.5. 不要忘记将build.xml中的更改还原为1.5。

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

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