为Android构建手机间隙应用程序失败

2022-09-03 05:12:49

当尝试为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)

我尝试在lib exec中将java_home设置为java别名,但仍然一无所获。关于可能导致问题的原因的任何想法?


答案 1

这是因为您的InAppBrowser插件已过时,并且可能与第一次安装插件时更新的Cordova Android平台版本不同步。我在InAppBrowser的cordova-android@4.0.0和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

现在再次构建,错误应该已经消失了。

编辑:我刚刚注意到在你的问题的顶部,你正在使用电话间隙。由于您用cordova标记(这就是我使用的),我用cordova命令回答,但我猜几乎相同的过程适用于Phonegap。


答案 2

cordova-android@4.0.0的相同问题 感谢的JDawgg,你的解决方案比我的更好,但是如果有人仍然有错误,你可以使用cordova-android@3.6.4,如下所示:

cordova platform remove android

然后

cordova platform add android@3.6.4

您必须安装安卓4.2.2 sdk

最后

sudo phonegap build android

推荐