Flutterfire: E/FlutterFcmService( 8641): Fatal: failed to find callback

Created on 3 Jun 2020  Â·  9Comments  Â·  Source: FirebaseExtended/flutterfire

I have the last version of flutter:

PS C:\Users\vasqu> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.17.2, on Microsoft Windows [Version 10.0.19041.264], locale es-EC)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Android Studio (version 4.0)
[√] VS Code (version 1.45.1)
[√] Connected device (1 available)

• No issues found!

I want to manage the background notification of Firebase Cloud Messaging.
But follogin the instructions of:

https://pub.dev/packages/firebase_messaging

Say that I have to add a java class Application.java in the same folder where is the MainActivity.java,
in the java folder, but the MainActivity is in the Kotlin folder with the name MainActivity.kt. I traslate the Application.java to kotlin and put the file Application.kt in the Kotlin folder.

But when I run the app I got the following error:

Firts in this method
override fun registerWith(registry: PluginRegistry) {
GeneratedPluginRegistrant.registerWith(registry)
}
I get this error:
Application.kt: (17, 48): Type mismatch: inferred type is PluginRegistry but FlutterEngine was expected

Then when I cast the registry param:

override fun registerWith(registry: PluginRegistry) {
    GeneratedPluginRegistrant.registerWith(registry as FlutterEngine)
}

And I get this error:
PlatformException (PlatformException(error, io.flutter.app.FlutterPluginRegistry cannot be cast to io.flutter.embedding.engine.FlutterEngine, null))

What I'm doing wrong?
Can you provide a crystal clear example of how to implement the background notification of FCM?

customer-response

Most helpful comment

hI @fuentestechsoft
Please try this

import android.os.Bundle
import io.flutter.embedding.android.FlutterActivity
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
import io.flutter.view.FlutterMain

class MainActivity : FlutterActivity(), PluginRegistry.PluginRegistrantCallback {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        FlutterFirebaseMessagingService.setPluginRegistrant(this);
        FlutterMain.startInitialization(this)
    }

    override fun registerWith(registry: PluginRegistry?) {
        if (!registry!!.hasPlugin("io.flutter.plugins.firebasemessaging")) {
            FirebaseMessagingPlugin.registerWith(registry!!.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
        }
    }

}

All 9 comments

hI @fuentestechsoft
Please try this

import android.os.Bundle
import io.flutter.embedding.android.FlutterActivity
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
import io.flutter.view.FlutterMain

class MainActivity : FlutterActivity(), PluginRegistry.PluginRegistrantCallback {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        FlutterFirebaseMessagingService.setPluginRegistrant(this);
        FlutterMain.startInitialization(this)
    }

    override fun registerWith(registry: PluginRegistry?) {
        if (!registry!!.hasPlugin("io.flutter.plugins.firebasemessaging")) {
            FirebaseMessagingPlugin.registerWith(registry!!.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
        }
    }

}

Thanks. With the suggested code, at lease compile and run.
But when in the emulator I close the app an send a push notification from postman, the app in background crash:

06-09 16:11:36.748  2007  2007 I GoogleInputMethod: onFinishInput() : Dummy InputConnection bound
06-09 16:11:36.749  2007  2007 I GoogleInputMethod: onStartInput() : Dummy InputConnection bound
06-09 16:11:36.780  2025  2252 D EGL_emulation: eglMakeCurrent: 0xdda85a20: ver 2 0 (tinfo 0xdda83d50)
06-09 16:11:37.052  1883  1898 I am_uid_running: 10086
06-09 16:11:36.831  2025  2252 D EGL_emulation: eglMakeCurrent: 0xdda85a20: ver 2 0 (tinfo 0xdda83d50)
06-09 16:11:37.079 31672 31672 I .flutter_push0: Not late-enabling -Xcheck:jni (already on)
06-09 16:11:37.080  1883  1900 I am_proc_start: [0,31672,10086,ec.com.vasquezjaime.flutter_push01,service,ec.com.vasquezjaime.flutter_push01/io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService]
06-09 16:11:37.080  1883  1900 I ActivityManager: Start proc 31672:ec.com.vasquezjaime.flutter_push01/u0a86 for service ec.com.vasquezjaime.flutter_push01/io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
06-09 16:11:37.096 31672 31672 W .flutter_push0: Unexpected CPU variant for X86 using defaults: x86
06-09 16:11:37.112  1883  4985 I am_proc_bound: [0,31672,ec.com.vasquezjaime.flutter_push01]
06-09 16:11:37.114  1883  4985 I am_uid_active: 10086
06-09 16:11:37.340 31672 31672 I FirebaseInitProvider: FirebaseApp initialization successful
06-09 16:11:37.355 31672 31700 I ResourceExtractor: Found extracted resources res_timestamp-1-1591736848443
06-09 16:11:37.419 31672 31692 I FA      : App measurement initialized, version: 21028
06-09 16:11:37.419 31672 31692 I FA      : To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
06-09 16:11:37.420 31672 31692 I FA      : To enable faster debug mode event logging run:
06-09 16:11:37.420 31672 31692 I FA      :   adb shell setprop debug.firebase.analytics.app ec.com.vasquezjaime.flutter_push01
06-09 16:11:37.585 31672 31672 D AndroidRuntime: Shutting down VM
06-09 16:11:37.586 31672 31672 E AndroidRuntime: FATAL EXCEPTION: main
06-09 16:11:37.586 31672 31672 E AndroidRuntime: Process: ec.com.vasquezjaime.flutter_push01, PID: 31672
06-09 16:11:37.586 31672 31672 E AndroidRuntime: java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.RuntimeException: PluginRegistrantCallback is not set.
06-09 16:11:37.586 31672 31672 E AndroidRuntime:    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3544)
06-09 16:11:37.586 31672 31672 E AndroidRuntime:    at android.app.ActivityThread.access$1300(ActivityThread.java:199)
06-09 16:11:37.586 31672 31672 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1666)
06-09 16:11:37.586 31672 31672 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:106)
06-09 16:11:37.586 31672 31672 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:193)
06-09 16:11:37.586 31672 31672 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:6669)
06-09 16:11:37.586 31672 31672 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
06-09 16:11:37.586 31672 31672 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
06-09 16:11:37.586 31672 31672 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
06-09 16:11:37.586 31672 31672 E AndroidRuntime: Caused by: java.lang.RuntimeException: PluginRegistrantCallback is not set.
06-09 16:11:37.586 31672 31672 E AndroidRuntime:    at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.startBackgroundIsolate(FlutterFirebaseMessagingService.java:157)
06-09 16:11:37.586 31672 31672 E AndroidRuntime:    at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.onCreate(FlutterFirebaseMessagingService.java:77)
06-09 16:11:37.586 31672 31672 E AndroidRuntime:    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3532)
06-09 16:11:37.586 31672 31672 E AndroidRuntime:    ... 8 more
06-09 16:11:37.587  1883 22176 I am_crash: [31672,0,ec.com.vasquezjaime.flutter_push01,814267974,java.lang.RuntimeException,PluginRegistrantCallback is not set.,FlutterFirebaseMessagingService.java,157]
06-09 16:11:37.589  1883  1899 I ActivityManager: Showing crash dialog for package ec.com.vasquezjaime.flutter_push01 u0
06-09 16:11:37.596  1883  1898 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.stats.service.DropBoxEntryAddedReceiver
06-09 16:11:37.596  1883  1898 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver
06-09 16:11:37.657  1883  2144 I GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$SvStatusInfo@aff8ba3)
06-09 16:11:37.658  1639  1639 D gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 3399680
06-09 16:11:37.678  1883  1897 I GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$SvStatusInfo@aff8ba3)
06-09 16:11:37.681  1639  1639 D gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 3399680
06-09 16:11:37.700  1639  1695 D gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 3399680
06-09 16:11:37.749  1883  4255 D EGL_emulation: eglMakeCurrent: 0xbfe87740: ver 2 0 (tinfo 0xbfefdb80)
06-09 16:11:37.804 31672 31712 I flutter : Observatory listening on http://127.0.0.1:40514/8cttYXstkJA=/
06-09 16:11:38.170  1883  1899 W Looper  : Slow dispatch took 460ms android.ui h=android.view.Choreographer$FrameHandler c=android.view.Choreographer$FrameDisplayEventReceiver@10e88a0 m=0
06-09 16:11:38.171  1883  1899 W Looper  : Slow delivery took 420ms android.ui h=android.view.Choreographer$FrameHandler c=android.view.Choreographer$FrameDisplayEventReceiver@10e88a0 m=0
06-09 16:11:38.171  1883  1899 W Looper  : Drained

Hi @fuentestechsoft
Using firebase_messaging: ^6.0.16 on official example, there is no crash in background when sending notification

Can you please try official exaple
Thank you


Hey @fuentestechsoft. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

image
Why i get this error??

We try a different aproach to the push notifications, we don't use onBackgroundMessage only use:

_firebaseMessaging.configure(
  onMessage: (info) {
  },      
  onLaunch: (info){
  },
  onResume: (info){
  }

Me too.

 Fatal: failed to find callback

in

android/app/src/main/kotlin/jp/company-name/app-name/MainActivity.kt
package jp.company-name.app-name

import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugins.deviceinfo.DeviceInfoPlugin
import io.flutter.plugins.firebase.core.FirebaseCorePlugin
import io.flutter.plugins.firebase.crashlytics.firebasecrashlytics.FirebaseCrashlyticsPlugin
import io.flutter.plugins.firebase.firebaseremoteconfig.FirebaseRemoteConfigPlugin
import io.flutter.plugins.firebaseanalytics.FirebaseAnalyticsPlugin
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService // <= I added
import io.flutter.plugins.packageinfo.PackageInfoPlugin
import io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin
import io.flutter.plugins.urllauncher.UrlLauncherPlugin

class MainActivity : FlutterActivity() {

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)

        flutterEngine.plugins.add(DeviceInfoPlugin())
        flutterEngine.plugins.add(FirebaseAnalyticsPlugin())
        flutterEngine.plugins.add(FirebaseCorePlugin())
        flutterEngine.plugins.add(FirebaseCrashlyticsPlugin())
        flutterEngine.plugins.add(FirebaseRemoteConfigPlugin())
        flutterEngine.plugins.add(FirebaseMessagingPlugin())
        flutterEngine.plugins.add(FlutterFirebaseMessagingService())  // <= I added but it cause error by gradle
        flutterEngine.plugins.add(PackageInfoPlugin())
        flutterEngine.plugins.add(SharedPreferencesPlugin())
        flutterEngine.plugins.add(UrlLauncherPlugin())

        val handler = MethodCallHandler(this)
        MethodChannel(flutterEngine.dartExecutor, MethodCallHandler.CHANNEL_NAME).setMethodCallHandler(handler)
    }
}

@TahaTesser
your MainActivity are different to mine.
I have configureFlutterEngine

image
Why i get this error??

the same problem did u solved the issue ?

Was this page helpful?
0 / 5 - 0 ratings