添加Firebase消息传递后的编译错误

时间:2019-10-01 16:43:23

标签: flutter compiler-errors firebase-cloud-messaging

对于应用程序开发,我需要Firebase云消息传递。 在我的pubsepc.yaml中,添加以下依赖项:firebase_messaging:^ 5.1.6

我暂时没有添加代码。

此后,我构建代码,但出现错误:

flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-5.1.6/android/src/main/java/io/flutter/plugins/firebasemessaging/FlutterFirebaseMessagingService.java:143: error: method findAppBundlePath in class FlutterMain cannot be applied to given types;
    String appBundlePath = FlutterMain.findAppBundlePath();
                                      ^
  required: Context
  found: no arguments
  reason: actual and formal argument lists differ in length
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':firebase_messaging: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. Run with --scan to get full insights.

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

BUILD FAILED in 1s
Finished with error: Gradle task assembleDebug failed with exit code 1

2 个答案:

答案 0 :(得分:6)

如果您使用Java并选中FlutterFirebaseMessagingService.java

FlutterMain.findAppBundlePath()

此处需要在参数中添加上下文,因此第一种解决方案是您可以在参数中添加上下文

FlutterMain.findAppBundlePath(context)

第二个解决方案从firebase_messaging: ^5.1.6中删除了pubspac.yaml的依存关系,并在终端中打flutter clean进行清理,现在添加firebase_messaging: 5.1.6 (不带^)并在终端中点击flutter pub get。此解决方案对我有用。

第二种解决方案是更好的做法。

答案 1 :(得分:0)

@Maddy的答案很明确。但是如果有人不能解决问题。

请尝试:flutter upgrade并做@Maddy回答

这对我有用。 很抱歉,我没有足够的声誉。