15

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?

5 Answers 5

24

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"
......
0
23

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.

9
  • Hi Jay, the provided link specifically states to create an application.kt file. May weI know what configuration you made in the manifest?
    – VipiN Negi
    Commented Mar 27, 2021 at 7:53
  • 1
    @VipiNNegi by configuration I mean setting up Application class as stated in the documentation itself. Note that this step is only required if and only if you are using flutter version below 1.12, else everything works out of the box.
    – Jay Dangar
    Commented Mar 27, 2021 at 7:57
  • As in your answer, you mentioned if Flutter v1.12 and above, no need to create application.kt. Did you mean to setup Application class in MainActivity.kt?
    – VipiN Negi
    Commented Mar 27, 2021 at 8:02
  • No i mean you don't have to do that configuration. just installing the pub.dev dependency should be enough.
    – Jay Dangar
    Commented Mar 27, 2021 at 8:28
  • 1
    Flutter 2.0.3 • channel stable
    – VipiN Negi
    Commented Mar 28, 2021 at 2:41
3

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
2

Hi had the same problem. I updated flutter for an app developed with flutter 1.xx.

When I installed firebase_messaging (version 7.0.3 using flutter 1.xx) I had to add Application.kt and FirebaseCloudMessagingPluginRegistrant.kt in the folder android\app\src\main\kotlin\com\xxx\yyy\FirebaseCloudMessagingPluginRegistrant.kt .

Now I'm using flutter 3.xx with firebasemessaging 11.1.0 and those file are no longer required.

If you delete those files you get rid of this error.

0

Currently I've the following code working fine with latest stable version of firebase_message package.

Try this code and check if it will work for you.

//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
        }
    }
}
1
  • 1
    Can you share your import statements? Commented Dec 22, 2020 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.