flutter - 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
解决方案
如果你去 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
终端。这个解决方案对我有用。
第二种解决方案是更好的做法。
推荐阅读
- reactjs - “无法读取未定义的属性'问题'” Reactjs
- sharepoint - 使用 Sharepoint 列表和流程自动化“Vlookup”
- typescript - 如何通过从具有值的对象中选择键来创建类型
- mysql - 根据唯一条件选择行
- docker - Docker compose:无法启动服务 nginx:地址已在使用中
- flutter - 如何用 Flutter 做这个底页?
- jenkins - 关于 Jenkins BitBucket 使用管道和管道脚本的问题,但在将新数据推送到 bitbucket 时也会运行
- node.js - macOS 10.13 brew install node@14 问题
- node.js - Express JS - 如果 MongoDB id 不存在则重定向/错误 [ERR_HTTP_HEADERS_SENT]:在将标头发送到客户端后无法设置标头
- vbscript - 手术失败。错误(62)输入超过文件结尾