Flutter 项目中的 Application.kt 给出错误 - 无法访问“com.google.firebase.messaging.zzf”

Posted

技术标签:

【中文标题】Flutter 项目中的 Application.kt 给出错误 - 无法访问“com.google.firebase.messaging.zzf”【英文标题】:Application.kt in flutter project giving error - Cannot access 'com.google.firebase.messaging.zzf' 【发布时间】:2021-02-09 12:03:33 【问题描述】:

My application.kt文件如下:

import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService


class Application : FlutterApplication(), PluginRegistrantCallback 
    override fun onCreate() 
        super.onCreate()
        FlutterFirebaseMessagingService.setPluginRegistrant(this)
    

    override fun registerWith(registry: PluginRegistry?) 
        io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
    


我得到的错误:

Cannot access 'com.google.firebase.messaging.zzf' which is a supertype 
of 'io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService'.
Check your module classpath for missing or conflicting dependencies

错误所在的行是 FlutterFirebaseMessagingService.setPluginRegistrant(this)

我的android/build.gradle 文件有以下实现代码:

dependencies 
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath 'com.google.gms:google-services:4.3.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    

我尝试了很多搜索,但仍然遇到这个问题。这里有什么问题?

【问题讨论】:

确保将类路径依赖项添加到 [project]/android/build.gradle 文件而不是 app/build.gradle 检查此链接 pub.dev/packages/firebase_messaging 以正确设置您的 Firebase 消息传递 class dependencyandroid/build.gradle 的一部分,而不是android/app/build.gradle`` as stated before. it was my mistake to put it in the post. app is configured as the package 状态的一部分。我不知道这个错误是什么意思! 【参考方案1】:

试试这个

android/build.gradle 中添加classpath 'com.google.gms:google-services:4.3.3'

android/app/build.gradle 中添加implementation "com.google.firebase:firebase-messaging:20.1.0"

试试这个

override fun registerWith(registry: PluginRegistry?) 
        registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin");
    

【讨论】:

我已经完成了这一切,最初恢复为4.3.2,因为这是官方文档所说的。不知道插件没有找到的东西有什么问题:/

以上是关于Flutter 项目中的 Application.kt 给出错误 - 无法访问“com.google.firebase.messaging.zzf”的主要内容,如果未能解决你的问题,请参考以下文章

Flutter-flutter run报错Could not build the application for the simulator.

Flutter入门:applicationmodulepackageplugin

如何通过 Dart/Flutter 中的“application/octet-stream”将 png 文件发送到 Microsoft Custom Vision?

集成 Flutter 到现有项目,并实现使用单个 FlutterEngine 管理多个入口

flutter与原生混编(iOS)

4.Flutter生命周期与路由管理