为 Android 构建 PhoneGap 应用失败

16

尝试构建我的 PhoneGap 应用程序以在 Android 上运行时,

sudo phonegap build android

出现以下错误:

:compileDebugJava
/Users/youssefsami/Library/Mobile Documents/com~apple~CloudDocs/Developer/Mobile Apps/UzuConvert/platforms/android/src/org/apache/cordova/inappbrowser/InAppBrowser.java:120: error: cannot find symbol

                                || Config.isUrlWhiteListed(url)) {
                                         ^

  symbol:   method isUrlWhiteListed(String)

  location: class Config

Note: Some input files use or override a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

1 error


FAILED



FAILURE: 
Build failed with an exception.



* What went wrong:

Execution failed for task ':compileDebugJava'.

> 
Compilation failed; see the compiler error output for details.



* Try:

Run with 
--stacktrace option to get the stack trace. Run with 
--info or 
--debug
 option to get more log output.



BUILD FAILED


Total time: 5.607 secs


/Users/youssefsami/Library/Mobile Documents/com~apple~CloudDocs/Developer/Mobile Apps/UzuConvert/platforms/android/cordova/node_modules/q/q.js:126
                    throw e;
                          ^

Error code 1 for command: /Users/youssefsami/Library/Mobile Documents/com~apple~CloudDocs/Developer/Mobile Apps/UzuConvert/platforms/android/gradlew with args: cdvBuildDebug,-b,/Users/youssefsami/Library/Mobile Documents/com~apple~CloudDocs/Developer/Mobile Apps/UzuConvert/platforms/android/build.gradle,-Dorg.gradle.daemon=true

ERROR building one of the platforms: Error: /Users/youssefsami/Library/Mobile Documents/com~apple~CloudDocs/Developer/Mobile Apps/UzuConvert/platforms/android/cordova/build: Command failed with exit code 1
You may not have the required environment or OS to build this project

Error: /Users/youssefsami/Library/Mobile Documents/com~apple~CloudDocs/Developer/Mobile Apps/UzuConvert/platforms/android/cordova/build: Command failed with exit code 1
    at ChildProcess.whenDone (/usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:131:23)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1015:16)
    at Process.ChildProcess._handle.onexit (child_process.js:1087:5)

我尝试将java_home设置为lib exec中的java别名,但仍然没有任何作用。有什么想法可能导致问题?


我在运行Ember-Cli-Cordova时遇到了相同的问题。 - Dan Green-Leipciger
3个回答

24

这是因为你的InAppBrowser插件已过时,可能与较新版本的Cordova Android平台不同步,而你最初安装插件时则不同。我在cordova-android@4.0.0和InAppBrowser 0.5.3中遇到了相同的问题。

解决方法是首先移除该插件。

cordova plugin rm org.apache.cordova.inappbrowser

然后再添加它(它应该会重新安装,使用cordova CLI的最新版本,在我的情况下它使用了0.6)。您可以在plugins/org.apache.cordova.inappbrowser/文件夹中的RELEASENOTES.md中检查版本。

cordova plugin add org.apache.cordova.inappbrowser

在重新构建之前,您需要移除 Android 平台并重新添加它,以便不会保留插件的旧版本。

cordova platform rm android

cordova platform add android

现在重新构建,错误应该已经消失了。

编辑:我刚注意到你的问题顶部提到了你正在使用Phonegap。因为你标记了cordova(这是我使用的),所以我用了cordova命令回答,但我猜想使用Phonegap几乎相同的过程也适用。


这个解决方案对我有用,应该被接受为答案。 - Tal
这个可行,尽管插件已经被重命名为 cordova plugin add cordova-plugin-inappbrowser - dakdad
我发现将版本明确设置为@1.0.1对我有用。 - occasl

4

cordova-android@4.0.0也存在同样的问题。感谢JDawgg提供的解决方案,但如果仍有人遇到此问题,可以使用cordova-android@3.6.4,方法如下:

cordova platform remove android

那么

cordova platform add android@3.6.4

您必须安装Android 4.2.2 SDK。

最后

sudo phonegap build android

1
如果有人正在使用Meteor并遇到同样的问题,martijnwalraven建议删除旧版本的cordova-plugin-inappbrowser并添加最新版本:
$ meteor remove cordova:cordova-plugin-inappbrowser
$ meteor add cordova:cordova-plugin-inappbrowser@1.0.1

这对我很有帮助!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接