Application.kt:未解决的参考:firebasemessaging

Posted

技术标签:

【中文标题】Application.kt:未解决的参考:firebasemessaging【英文标题】:Application.kt: Unresolved reference: firebasemessaging 【发布时间】:2021-04-01 03:49:32 【问题描述】:

我正在尝试将firebase_messaging 更新到新版本8.0.0-dev.10

但是,我收到以下错误:

Running Gradle task 'assembleDebug'...
Application.kt: (5, 27): Unresolved reference: firebasemessaging
Application.kt: (6, 27): Unresolved reference: firebasemessaging
Application.kt: (11, 9): Unresolved reference: FlutterFirebaseMessagingService
Application.kt: (15, 9): Unresolved reference: FirebaseMessagingPlugin

这就是我的 Application.kt 的样子

package com.example.opengames

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

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

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

有什么想法吗?

【问题讨论】:

【参考方案1】:

你可以如下修复它,创建Application.kt文件

package com.example.YOUR.PACKAGE

import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry

import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin

class Application() : FlutterApplication(), PluginRegistry.PluginRegistrantCallback 
  override fun registerWith(registry: PluginRegistry?) 
      val key: String? = FlutterFirebaseMessagingPlugin::class.java.canonicalName
      if (!registry?.hasPlugin(key)!!) 
          FlutterFirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin"));
        
    

并在您的清单中更改为:

 <application
        android:label="El Chaski Customer"
        android:name=".Application"
        android:icon="@mipmap/launcher_icon">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
......

【讨论】:

【参考方案2】:

来自官方文档

https://firebase.flutter.dev/docs/messaging/overview#3-android-integration

据此,如果您使用的是 Flutter 1.12 及更高版本,则不需要在 application.kt 中进行额外的集成。它开箱即用。

【讨论】:

嗨,Jay,所提供的链接明确说明要创建一个 application.kt 文件。我们可以知道你在清单中做了什么配置吗? @VipiNNegi 通过配置我的意思是设置应用程序类,如文档本身所述。请注意,仅当且仅当您使用低于 1.12 的 Flutter 版本时才需要此步骤,否则一切正常。 如您的回答,您提到如果 Flutter v1.12 及更高版本,则无需创建 application.kt。您的意思是在 MainActivity.kt 中设置 Application 类吗? 不,我的意思是您不必进行该配置。只需安装 pub.dev 依赖项就足够了。 Flutter 2.0.3 • 频道稳定【参考方案3】:

目前,我的以下代码与最新稳定版本的 firebase_message 软件包一起正常工作。

试试这个代码,看看它是否适合你。

//package your.app.package

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

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

    override fun registerWith(registry: PluginRegistry) 
        FirebaseCloudMessagingPluginRegistrant.registerWith(registry)
    


class FirebaseCloudMessagingPluginRegistrant 
    companion object 
        fun registerWith(registry: PluginRegistry) 
            if (alreadyRegisteredWith(registry)) 
                return;
            
            FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
        

        private fun alreadyRegisteredWith(registry: PluginRegistry): Boolean 
            val key = FirebaseCloudMessagingPluginRegistrant::class.java.name
            if (registry.hasPlugin(key)) 
                return true
            
            registry.registrarFor(key)
            return false
        
    

【讨论】:

你能分享你的进口声明吗?

以上是关于Application.kt:未解决的参考:firebasemessaging的主要内容,如果未能解决你的问题,请参考以下文章

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

斐讯 FIR151M 频繁掉线(OpenWRT解决方案)

未找到 Ktor 会话

Swift 2.3 pod 更新后使用未解析的标识符 Firebase 'FIR'

移动端持续集成(Jenkins+Gradle+fir.im)

python中怎么生成基于窗函数的fir滤波器