4

I am using Firebase messaging and when I got notification from firebase console my application shutdown with this exception can anyone please suggest me what should I have to do i am fighting with this issue for more than 2 hours now

My firebase messagin version is firebase_messaging: ^6.0.16

My dependendency for the firebaseMessaging is implementation 'com.google.firebase:firebase-messaging:20.2.3'

java.lang.RuntimeException: Unable to instantiate service com.samriddh.partner.java.MyFirebaseMessagingService: java.lang.ClassNotFoundException: Didn't find class "com.samriddh.partner.java.MyFirebaseMessagingService" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.samriddh.partner-ameKbTimiGALFObiP3aUeg==/base.apk"],nativeLibraryDirectories=[/data/app/com.samriddh.partner-ameKbTimiGALFObiP3aUeg==/lib/arm64, /data/app/com.samriddh.partner-ameKbTimiGALFObiP3aUeg==/base.apk!/lib/arm64-v8a, /system/lib64]]

My android Manifest.xml file is

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.samriddh.partner">
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
         <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <application
        android:name=".Application"
        android:label="samriddh partner"
        android:icon="@mipmap/launcher_icon">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <!-- Displays an Android View that continues showing the launch screen
                 Drawable until Flutter paints its first frame, then this splash
                 screen fades out. A splash screen is useful to avoid any visual
                 gap between the end of Android's launch screen and the painting of
                 Flutter's first frame. -->
            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />
          <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
          </intent-filter>
          <intent-filter>
              <action android:name="android.intent.action.MAIN"/>
              <category android:name="android.intent.category.LAUNCHER"/>
          </intent-filter>
        </activity>

        <meta-data android:name="com.google.android.geo.API_KEY"
          android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/>

        <uses-library android:name="org.apache.http.legacy" android:required="false"/>
        
        <meta-data android:name="flutterEmbedding" android:value="2" />
        
        <service android:name=".service.MyFirebaseMessagingService"> </service>
        
        <service android:name=".java.MyFirebaseMessagingService" android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>    
        </service>    
    </application>
</manifest>

and my Application.kt file is

package com.samriddh.partner

import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.GeneratedPluginRegistrant
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"));
    }
}
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Keshav Suman
  • 75
  • 2
  • 6

5 Answers5

3

Making class public solved the problem for me.

Mateusz Kaflowski
  • 2,221
  • 1
  • 29
  • 35
2

The error is telling you that Android can't find the service you declared with the the full class name "com.samriddh.partner.java.MyFirebaseMessagingService". Either you never added this class, or you told Android the wrong name in the manifest.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Can you please tell me what i have to do now ?? i am new to this and I am able to run my application but when application receives notification it shut downs unexpectedly – Keshav Suman Sep 20 '20 at 23:28
  • 1
    It sounds like you didn't complete the documented instructions to integration FCM into your app. – Doug Stevenson Sep 21 '20 at 06:09
2
    <!-- THIS IS CRASHING THE PUSH NOTIFICATION -->    
    <!-- <service
        android:name=".java.MyFirebaseMessagingService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service> -->
Carlton Foster
  • 141
  • 2
  • 7
0

Check if the package on the top is the correct. ex.

package com.samriddh.partner

If you copy/paste (like dummy me) from an example, it has some other package.

package com.google.firebase.quickstart.fcm.kotlin
paakjis
  • 369
  • 4
  • 16
0

At the time of writing I am using flutter firebase_messaging package v14.2.3. and I need this in order to recieve FCM messages in direct boot mode (while app is not started).

I have opened the project in Android Studio and looked for the FlutterFirebaseMessagingService class in imported packages.

The fix that worked for me was using this class name io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingService in android/app/src/main/AndroidManifest.xml:

        <service
            android:name="io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>        
seven
  • 2,388
  • 26
  • 28