Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application.kt: Unresolved reference: firebasemessaging

I am trying to update firebase_messaging to the new version 8.0.0-dev.10.

However, I am getting these errors:

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

This is what my Application.kt looks like

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"))
    }
}

Any ideas?

like image 780
João Abrantes Avatar asked Dec 22 '20 12:12

João Abrantes


3 Answers

If Your Flutter Version >= 1.12, then just delete Application.kt and FirebaseCloudMessagingPluginRegistrant.kt if exist. As these additional steps are not required anymore in android. then run

flutter clean 

flutter run
like image 127
Mohammad Avatar answered Sep 21 '22 08:09

Mohammad


You can fix it as follows, create the Application.kt file

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"));
        }
    }
}

and in your Manifest change to:

 <application
        android:label="El Chaski Customer"
        android:name=".Application"
        android:icon="@mipmap/launcher_icon">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
......
like image 22
Alejandro Mancilla Avatar answered Nov 11 '22 05:11

Alejandro Mancilla


From official documentation

https://firebase.flutter.dev/docs/messaging/overview#3-android-integration enter image description here

According to this, if you are using Flutter version 1.12 and high, you require no additional integration inside application.kt. it works out of the box.

like image 22
Jay Dangar Avatar answered Nov 11 '22 03:11

Jay Dangar