Flutter 添加firebase消息传递后的编译错误
对于应用程序开发,我需要firebase云消息。 在我的pubsepc.yaml中,我添加了以下依赖项:firebase\u消息:^5.1.6 我暂时没有添加代码 之后我生成代码,出现错误:Flutter 添加firebase消息传递后的编译错误,flutter,compiler-errors,firebase-cloud-messaging,Flutter,Compiler Errors,Firebase Cloud Messaging,对于应用程序开发,我需要firebase云消息。 在我的pubsepc.yaml中,我添加了以下依赖项:firebase\u消息:^5.1.6 我暂时没有添加代码 之后我生成代码,出现错误: flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-5.1.6/android/src/main/java/io/flutter/plugins/firebasemessaging/FlutterFirebaseMessagingSer
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
如果您转到Java并选中FirebaseMessagingService.Java
FlutterMain.findAppBundlePath()
这里的参数中需要上下文,所以第一个解决方案是在这里,您可以像这样在参数中添加上下文
FlutterMain.findAppBundlePath(context)
第二种解决方案是从pubspac.yaml
中删除firebase\u消息:^5.1.6
依赖项,并在终端中点击flatter clean
进行清理,现在在终端中添加firebase\u消息:5.1.6
(无^)并点击flatter pub get
。这个解决方案对我有效
第二个解决方案是更好的实践。关于@Maddy的答案很清楚。但是如果有人没有解决问题 请尝试:
flatter升级
并执行@Maddy应答
这对我有用。
很抱歉新的线程回答,我没有足够的声誉您是否添加了软件包自述中描述的android集成?谢谢,这对我来说很有用。但我将版本更改为firebase_messaging:5.0.0。第二个解决方案是为我工作,然后在pubspec上执行颤振升级选项。yamlYou应将您的答案作为注释发布在@Maddy answer下