I am unable to send notifications to my app from firebase, as it crashes everytime i do so

It previously showed error for latest versions of the firebase_messaging plugin, so i kept it empty so that the ide will get the latest packages.

These are my dependencies in pubspec.yaml file

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  #firebase_auth: ^0.10.0+1
  #firebase_core: ^0.4.0
  firebase_database: ^3.0.0
  firebase_messaging:
dev_dependencies:

My code for the push notifications is as follows:

firebaseMessaging.getToken().then((token){
      print("Token: $token");
    });

    firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        print('on message $message');
        final notification=message['notification'];
        setState(() {
          messages.add(Message(
              title: notification['title'],body: notification['body']
          ));
        });
      },
      onResume: (Map<String, dynamic> message) async {
        print('on resume $message');
      },
      onLaunch: (Map<String, dynamic> message) async {
        print('on launch $message');
      },
    );

This the logcat summary when i run my program:

 Syncing files to device SM G960F...
    D/[email protected][MainActivity](21660): MSG_WINDOW_FOCUS_CHANGED 1 1
    D/InputMethodManager(21660): prepareNavigationBarInfo() [email protected][MainActivity]
    D/InputMethodManager(21660): getNavigationBarColor() -855310
    D/InputMethodManager(21660): prepareNavigationBarInfo() [email protected][MainActivity]
    D/InputMethodManager(21660): getNavigationBarColor() -855310
    V/InputMethodManager(21660): Starting input: tba=com.kashyap.user_admin ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
    D/InputMethodManager(21660): startInputInner - Id : 0
    I/InputMethodManager(21660): startInputInner - mService.startInputOrWindowGainedFocus
    D/InputTransport(21660): Input channel constructed: fd=105
    D/InputMethodManager(21660): prepareNavigationBarInfo() [email protected][MainActivity]
    D/InputMethodManager(21660): getNavigationBarColor() -855310
    V/InputMethodManager(21660): Starting input: tba=com.kashyap.user_admin ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
    D/InputMethodManager(21660): startInputInner - Id : 0
    D/[email protected][MainActivity](21660): ViewPostIme pointer 0
    D/[email protected][MainActivity](21660): ViewPostIme pointer 1
    D/[email protected][MainActivity](21660): MSG_WINDOW_FOCUS_CHANGED 0 1
    D/InputMethodManager(21660): prepareNavigationBarInfo() [email protected][MainActivity]
    D/InputMethodManager(21660): getNavigationBarColor() -855310
    D/SurfaceView(21660): windowStopped(true) false 7c74c04 of [email protected][MainActivity]
    D/SurfaceView(21660): show() Surface(name=SurfaceView - com.kashyap.user_admin/[email protected]@0[21660])/@0x81cc5ed io.flutter.view.FlutterView{7c74c04 VFE...... ........ 0,0-1440,2960}
    D/SurfaceView(21660): surfaceDestroyed callback.size 1 #1 io.flutter.view.FlutterView{7c74c04 VFE...... ........ 0,0-1440,2960}
    W/libEGL  (21660): EGLNativeWindowType 0x72580fe010 disconnect failed
    D/SurfaceView(21660): destroy() Surface(name=SurfaceView - com.kashyap.user_admin/[email protected]@0[21660])/@0x81cc5ed io.flutter.view.FlutterView{7c74c04 VFE...... ........ 0,0-1440,2960}
    D/SurfaceView(21660): onWindowVisibilityChanged(4) false 7c74c04 of [email protected][MainActivity]
    W/libEGL  (21660): EGLNativeWindowType 0x726fef2010 disconnect failed
    D/OpenGLRenderer(21660): eglDestroySurface = 0x7266249a00, 0x726fef2000
    D/[email protected][MainActivity](21660): Relayout returned: old=[0,0][1440,2960] new=[0,0][1440,2960] result=0x5 surface={valid=false 0} changed=true
    D/InputTransport(21660): Input channel destroyed: fd=105
    D/SurfaceView(21660): onWindowVisibilityChanged(8) false 7c74c04 of [email protected][MainActivity]
    D/[email protected][MainActivity](21660): Relayout returned: old=[0,0][1440,2960] new=[0,0][1440,2960] result=0x1 surface={valid=false 0} changed=false
    I/hyap.user_admi(21660): Rejecting re-init on previously-failed class java.lang.Class<com.google.firebase.messaging.FirebaseMessagingService>: java.lang.IllegalAccessError: Class com.google.firebase.iid.zzb extended by class com.google.firebase.messaging.FirebaseMessagingService is inaccessible (declaration of 'com.google.firebase.messaging.FirebaseMessagingService' appears in /data/app/com.kashyap.user_admin-P6LJr-bNg8zLx2ZhadHMPA==/base.apk!classes2.dex)
    I/hyap.user_admi(21660):   at java.lang.Class java.lang.VMClassLoader.findLoadedClass(java.lang.ClassLoader, java.lang.String) (VMClassLoader.java:-2)
    I/hyap.user_admi(21660):   at java.lang.Class java.lang.ClassLoader.findLoadedClass(java.lang.String) (ClassLoader.java:738)
    I/hyap.user_admi(21660):   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:363)
    I/hyap.user_admi(21660):   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
    I/hyap.user_admi(21660):   at android.app.Service android.app.AppComponentFactory.instantiateService(java.lang.ClassLoader, java.lang.String, android.content.Intent) (AppComponentFactory.java:103)
    I/hyap.user_admi(21660):   at android.app.Service androidx.core.app.CoreComponentFactory.instantiateService(java.lang.ClassLoader, java.lang.String, android.content.Intent) (CoreComponentFactory.java:68)
    I/hyap.user_admi(21660):   at void android.app.ActivityThread.handleCreateService(android.app.ActivityThread$CreateServiceData) (ActivityThread.java:3710)
    I/hyap.user_admi(21660):   at void android.app.ActivityThread.access$1400(android.app.ActivityThread, android.app.ActivityThread$CreateServiceData) (ActivityThread.java:235)
    I/hyap.user_admi(21660):   at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1784)
    I/hyap.user_admi(21660):   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
    I/hyap.user_admi(21660):   at void android.os.Looper.loop() (Looper.java:214)
    I/hyap.user_admi(21660):   at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6981)
    I/hyap.user_admi(21660):   at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
    I/hyap.user_admi(21660):   at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:493)
    I/hyap.user_admi(21660):   at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:1445)
    I/hyap.user_admi(21660): 
    I/hyap.user_admi(21660): Rejecting re-init on previously-failed class java.lang.Class<io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService>: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/messaging/FirebaseMessagingService;
    I/hyap.user_admi(21660):   at java.lang.Class java.lang.VMClassLoader.findLoadedClass(java.lang.ClassLoader, java.lang.String) (VMClassLoader.java:-2)
    I/hyap.user_admi(21660):   at java.lang.Class java.lang.ClassLoader.findLoadedClass(java.lang.String) (ClassLoader.java:738)
    I/hyap.user_admi(21660):   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:363)
    I/hyap.user_admi(21660):   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
    I/hyap.user_admi(21660):   at android.app.Service android.app.AppComponentFactory.instantiateService(java.lang.ClassLoader, java.lang.String, android.content.Intent) (AppComponentFactory.java:103)
    I/hyap.user_admi(21660):   at android.app.Service androidx.core.app.CoreComponentFactory.instantiateService(java.lang.ClassLoader, java.lang.String, android.content.Intent) (CoreComponentFactory.java:68)
    I/hyap.user_admi(21660):   at void android.app.ActivityThread.handleCreateService(android.app.ActivityThread$CreateServiceData) (ActivityThread.java:3710)
    I/hyap.user_admi(21660):   at void android.app.ActivityThread.access$1400(android.app.ActivityThread, android.app.ActivityThread$CreateServiceData) (ActivityThread.java:235)
    I/hyap.user_admi(21660):   at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1784)
    I/hyap.user_admi(21660):   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
    I/hyap.user_admi(21660):   at void android.os.Looper.loop() (Looper.java:214)
    I/hyap.user_admi(21660):   at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6981)
    I/hyap.user_admi(21660):   at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
    I/hyap.user_admi(21660):   at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:493)
    I/hyap.user_admi(21660):   at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:1445)
    I/hyap.user_admi(21660): Caused by: java.lang.ClassNotFoundException: com.google.firebase.messaging.FirebaseMessagingService
    I/hyap.user_admi(21660):   at java.lang.Class java.lang.VMClassLoader.findLoadedClass(java.lang.ClassLoader, java.lang.String) (VMClassLoader.java:-2)
    I/hyap.user_admi(21660):   at java.lang.Class java.lang.ClassLoader.findLoadedClass(java.lang.String) (ClassLoader.java:738)
    I/hyap.user_admi(21660):   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:363)
    I/hyap.user_admi(21660):   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
    I/hyap.user_admi(21660):   at java.lang.Class java.lang.VMClassLoader.findLoadedClass(java.lang.ClassLoader, java.lang.String) (VMClassLoader.java:-2)
    I/hyap.user_admi(21660):   at java.lang.Class java.lang.ClassLoader.findLoadedClass(java.lang.String) (ClassLoader.java:738)
    I/hyap.user_admi(21660):   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:363)
    I/hyap.user_admi(21660):   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
    I/hyap.user_admi(21660):   at android.app.Service android.app.AppComponentFactory.instantiateService(java.lang.ClassLoader, java.lang.String, android.content.Intent) (AppComponentFactory.java:103)
    I/hyap.user_admi(21660):   at android.app.Service androidx.core.app.CoreComponentFactory.instantiateService(java.lang.ClassLoader, java.lang.String, android.content.Intent) (CoreComponentFactory.java:68)
    I/hyap.user_admi(21660):   at void android.app.ActivityThread.handleCreateService(android.app.ActivityThread$CreateServiceData) (ActivityThread.java:3710)
    I/hyap.user_admi(21660):   at void android.app.ActivityThread.access$1400(android.app.ActivityThread, android.app.ActivityThread$CreateServiceData) (ActivityThread.java:235)
    I/hyap.user_admi(21660):   at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1784)
    I/hyap.user_admi(21660):   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
    I/hyap.user_admi(21660):   at void android.os.Looper.loop() (Looper.java:214)
    I/hyap.user_admi(21660):   at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6981)
    I/hyap.user_admi(21660):   at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
    I/hyap.user_admi(21660):   at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:493)
    I/hyap.user_admi(21660):   at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:1445)
    I/hyap.user_admi(21660): 
    D/AndroidRuntime(21660): Shutting down VM
    E/AndroidRuntime(21660): FATAL EXCEPTION: main
    E/AndroidRuntime(21660): Process: com.kashyap.user_admin, PID: 21660
    E/AndroidRuntime(21660): java.lang.RuntimeException: Unable to instantiate service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.ClassNotFoundException: Didn't find class "io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService" on path: DexPathList[[zip file "/data/app/com.kashyap.user_admin-P6LJr-bNg8zLx2ZhadHMPA==/base.apk"],nativeLibraryDirectories=[/data/app/com.kashyap.user_admin-P6LJr-bNg8zLx2ZhadHMPA==/lib/arm64, /data/app/com.kashyap.user_admin-P6LJr-bNg8zLx2ZhadHMPA==/base.apk!/lib/arm64-v8a, /system/lib64]]
    E/AndroidRuntime(21660):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3715)
    E/AndroidRuntime(21660):    at android.app.ActivityThread.access$1400(ActivityThread.java:235)
    E/AndroidRuntime(21660):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1784)
    E/AndroidRuntime(21660):    at android.os.Handler.dispatchMessage(Handler.java:106)
    E/AndroidRuntime(21660):    at android.os.Looper.loop(Looper.java:214)
    E/AndroidRuntime(21660):    at android.app.ActivityThread.main(ActivityThread.java:6981)
    E/AndroidRuntime(21660):    at java.lang.reflect.Method.invoke(Native Method)
    E/AndroidRuntime(21660):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    E/AndroidRuntime(21660):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
    E/AndroidRuntime(21660): Caused by: java.lang.ClassNotFoundException: Didn't find class "io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService" on path: DexPathList[[zip file "/data/app/com.kashyap.user_admin-P6LJr-bNg8zLx2ZhadHMPA==/base.apk"],nativeLibraryDirectories=[/data/app/com.kashyap.user_admin-P6LJr-bNg8zLx2ZhadHMPA==/lib/arm64, /data/app/com.kashyap.user_admin-P6LJr-bNg8zLx2ZhadHMPA==/base.apk!/lib/arm64-v8a, /system/lib64]]
    E/AndroidRuntime(21660):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    E/AndroidRuntime(21660):    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    E/AndroidRuntime(21660):    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    E/AndroidRuntime(21660):    at android.app.AppComponentFactory.instantiateService(AppComponentFactory.java:103)
    E/AndroidRuntime(21660):    at androidx.core.app.CoreComponentFactory.instantiateService(CoreComponentFactory.java:68)
    E/AndroidRuntime(21660):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3710)
    E/AndroidRuntime(21660):    ... 8 more
    E/AndroidRuntime(21660):    Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/messaging/FirebaseMessagingService;
    E/AndroidRuntime(21660):        at java.lang.VMClassLoader.findLoadedClass(Native Method)
    E/AndroidRuntime(21660):        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
    E/AndroidRuntime(21660):        at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
    E/AndroidRuntime(21660):        ... 12 more
    E/AndroidRuntime(21660):    Caused by: java.lang.ClassNotFoundException: com.google.firebase.messaging.FirebaseMessagingService
    E/AndroidRuntime(21660):        at java.lang.VMClassLoader.findLoadedClass(Native Method)
    E/AndroidRuntime(21660):        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
    E/AndroidRuntime(21660):        at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
    E/AndroidRuntime(21660):        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    E/AndroidRuntime(21660):        ... 15 more
    E/AndroidRuntime(21660):    Caused by: java.lang.IllegalAccessError: Class com.google.firebase.iid.zzb extended by class com.google.firebase.messaging.FirebaseMessagingService is inaccessible (declaration of 'com.google.firebase.messaging.FirebaseMessagingService' appears in /data/app/com.kashyap.user_admin-P6LJr-bNg8zLx2ZhadHMPA==/base.apk!classes2.dex)
    E/AndroidRuntime(21660):        ... 15 more
    I/Process (21660): Sending signal. PID: 21660 SIG: 9
    Lost connection to device.

2 Answers

0
OneLunch Man On

This GitHub issue/comment suggests you need to pay very close attention to the plugin versions you are using. This means you'll also have to keep the platform specific dependencies updated as well (this for Android).

From the Firebase docs:

app/build.gradle:
implementation 'com.google.firebase:firebase-messaging:18.0.0'
0
Community On

The code started working when i added lates firebase core plugin and enabled androidx along with changing the gradle version from 5.1.1 to 4.10.2 and the gradle dependency in project level build.gradle to

   classpath 'com.android.tools.build:gradle:3.3.0'

instead of:

classpath 'com.android.tools.build:gradle:3.4.0'