Cordova-plugin-facebook4 - 无法构建离子应用程序

Posted

技术标签:

【中文标题】Cordova-plugin-facebook4 - 无法构建离子应用程序【英文标题】:Cordova-plugin-facebook4 - can't build ionic application 【发布时间】:2018-12-12 02:43:26 【问题描述】:

我正在尝试在 android 模拟器中构建一个 Ionic 应用程序,但奇怪的是我无法构建该应用程序。当我运行 ionic cordova run android 构建失败并出现以下错误:

 symbol:   class GraphRequest
 location: class ConnectPlugin
/home/hudson/projetos/brazil-cartoon/brazil-cartoon-app/platforms/android/app/src/main/java/org/apache/cordova/facebook/ConnectPlugin.java:761: error: cannot find symbol
    GraphRequest graphRequest = GraphRequest.newGraphpathRequest(AccessToken.getCurrentAccessToken(), graphAction, new GraphRequest.Callback() 
                                                                 ^
 symbol:   variable AccessToken
 location: class ConnectPlugin
/home/hudson/projetos/brazil-cartoon/brazil-cartoon-app/platforms/android/app/src/main/java/org/apache/cordova/facebook/ConnectPlugin.java:761: error: package GraphRequest does not exist
    GraphRequest graphRequest = GraphRequest.newGraphPathRequest(AccessToken.getCurrentAccessToken(), graphAction, new GraphRequest.Callback() 
                                                                                                                                   ^
/home/hudson/projetos/brazil-cartoon/brazil-cartoon-app/platforms/android/app/src/main/java/org/apache/cordova/facebook/ConnectPlugin.java:761: error: cannot find symbol
    GraphRequest graphRequest = GraphRequest.newGraphPathRequest(AccessToken.getCurrentAccessToken(), graphAction, new GraphRequest.Callback() 
                                ^
 symbol:   variable GraphRequest
 location: class ConnectPlugin
/home/hudson/projetos/brazil-cartoon/brazil-cartoon-app/platforms/android/app/src/main/java/org/apache/cordova/facebook/ConnectPlugin.java:810: error: cannot find symbol
    final AccessToken accessToken = AccessToken.getCurrentAccessToken();
          ^
 symbol:   class AccessToken
 location: class ConnectPlugin
/home/hudson/projetos/brazil-cartoon/brazil-cartoon-app/platforms/android/app/src/main/java/org/apache/cordova/facebook/ConnectPlugin.java:810: error: cannot find symbol
    final AccessToken accessToken = AccessToken.getCurrentAccessToken();
                                    ^
 symbol:   variable AccessToken
 location: class ConnectPlugin
/home/hudson/projetos/brazil-cartoon/brazil-cartoon-app/platforms/android/app/src/main/java/org/apache/cordova/facebook/ConnectPlugin.java:864: error: cannot find symbol
    if (error instanceof FacebookServiceException) 
                         ^
 symbol:   class FacebookServiceException
 location: class ConnectPlugin
/home/hudson/projetos/brazil-cartoon/brazil-cartoon-app/platforms/android/app/src/main/java/org/apache/cordova/facebook/ConnectPlugin.java:865: error: cannot find symbol
        return getFacebookRequestErrorResponse(((FacebookServiceException) error).getRequestError());
                                                 ^
 symbol:   class FacebookServiceException
 location: class ConnectPlugin
/home/hudson/projetos/brazil-cartoon/brazil-cartoon-app/platforms/android/app/src/main/java/org/apache/cordova/facebook/ConnectPlugin.java:870: error: cannot find symbol
    if (error instanceof FacebookDialogException) 
                         ^
 symbol:   class FacebookDialogException
 location: class ConnectPlugin
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
100 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> 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.

* Get more help at https://help.gradle.org

BUILD FAILED in 6s
at ChildProcess.whenDone (/home/hudson/projetos/brazil-cartoon/brazil-cartoon-app/platforms/android/cordova/node_modules/cordova-common/src/superspawn.js:169:23)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at maybeClose (internal/child_process.js:925:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
[2K[G(node:13843) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
[2K[G(node:13843) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

问题可能出在cordova-plugin-facebook4 上,因为它在我删除此插件时有效。我已按照插件页面中的 Android 指南说明进行操作,但不知道如何解决。 有什么办法可以解决这个问题并使用这个插件吗?

离子:3.20.0 科尔多瓦:8.0.0 cordova-plugin-facebook4: 2.2.0

【问题讨论】:

ionic Cordova 和 facebook 插件的版本? @NullPointer 添加了问题中的信息。 你有没有检查过平台目录下插件是否安装正确?同样添加插件后,在Android studio中打开项目n检查是否有编译时错误 【参考方案1】:

只需检查一个工作正常的特定版本1.7.4,因此请尝试使用以下命令

ionic cordova plugin add cordova-plugin-facebook4@1.7.4 --variable APP_ID="xxxxx" --variable APP_NAME="XXXX XXXX"

【讨论】:

以上是关于Cordova-plugin-facebook4 - 无法构建离子应用程序的主要内容,如果未能解决你的问题,请参考以下文章

需要PhoneGap项目的示例cordova-plugin-facebook4

cordova-plugin-facebook4 - 带有“未登录:您尚未登录。请登录并重试”的空白对话框

Cordova 脸书插件

跟踪 Ionic 应用中的 Facebook 应用安装

ionic 2中的本机facebook登录

如何使用 Cordova 向 iOS 上的 Facebook 好友发送邀请?