首页 > 解决方案 > Error of compilation after add firebase messaging

问题描述

For an applications development I need firebase cloud messaging. In my pubsepc.yaml I add this dependencies : firebase_messaging: ^5.1.6

I don't have add code for the moment.

Afterward I build code and I have error :

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

标签: fluttercompiler-errorsfirebase-cloud-messaging

解决方案


如果你去 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终端。这个解决方案对我有用。

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


推荐阅读