Ad

My App Crashed Everytime I Send Notification From Firebase Cloud Messaging

I want to send notification from FCM to my device, but my app always stopped working every time I send a notification. What could be the problem?

Here's some of my code

// app-level build.gradle
dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.firebase:firebase-core:16.0.9'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.support:design:27.1.0'
    implementation 'com.google.firebase:firebase-messaging:17.3.3'
}

// project-level build.gradle

dependencies {
    classpath 'com.android.tools.build:gradle:3.3.1'
    classpath 'com.google.gms:google-services:4.2.0'
}

AndroidManifest.xml

<intent-filter>
    <action android:name="FLUTTER_NOTIFICATION_CLICK"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  cloud_firestore:
  firebase_core: 
  firebase_messaging: 
  cupertino_icons: ^0.1.2

dev_dependencies:

error log:

E/AndroidRuntime(17164): 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.maztur.hunafa-z3QygagDkOlt4fQ6fzLBgw==/base.apk"],nativeLibraryDirectories=[/data/app/com.maztur.hunafa-z3QygagDkOlt4fQ6fzLBgw==/lib/arm64, /data/app/com.maztur.hunafa-z3QygagDkOlt4fQ6fzLBgw==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]
E/AndroidRuntime(17164):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3737)
E/AndroidRuntime(17164):    at android.app.ActivityThread.access$1400(ActivityThread.java:237)
E/AndroidRuntime(17164):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1801)
E/AndroidRuntime(17164):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(17164):    at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime(17164):    at android.app.ActivityThread.main(ActivityThread.java:7045)
E/AndroidRuntime(17164):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(17164):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime(17164):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
E/AndroidRuntime(17164): Caused by: java.lang.ClassNotFoundException: Didn't find class "io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService" on path: DexPathList[[zip file "/data/app/com.maztur.hunafa-z3QygagDkOlt4fQ6fzLBgw==/base.apk"],nativeLibraryDirectories=[/data/app/com.maztur.hunafa-z3QygagDkOlt4fQ6fzLBgw==/lib/arm64, /data/app/com.maztur.hunafa-z3QygagDkOlt4fQ6fzLBgw==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]
E/AndroidRuntime(17164):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
E/AndroidRuntime(17164):    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime(17164):    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime(17164):    at android.app.AppComponentFactory.instantiateService(AppComponentFactory.java:103)
E/AndroidRuntime(17164):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3732)
E/AndroidRuntime(17164):    ... 8 more
E/AndroidRuntime(17164):    Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/messaging/FirebaseMessagingService;
E/AndroidRuntime(17164):        at java.lang.VMClassLoader.findLoadedClass(Native Method)
E/AndroidRuntime(17164):        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
E/AndroidRuntime(17164):        at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
E/AndroidRuntime(17164):        ... 11 more
E/AndroidRuntime(17164):    Caused by: java.lang.ClassNotFoundException: com.google.firebase.messaging.FirebaseMessagingService
E/AndroidRuntime(17164):        at java.lang.VMClassLoader.findLoadedClass(Native Method)
E/AndroidRuntime(17164):        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
E/AndroidRuntime(17164):        at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
E/AndroidRuntime(17164):        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime(17164):        ... 14 more
E/AndroidRuntime(17164):    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.maztur.hunafa-z3QygagDkOlt4fQ6fzLBgw==/base.apk!classes2.dex)
E/AndroidRuntime(17164):        ... 14 more
I/Process (17164): Sending signal. PID: 17164 SIG: 9
Lost connection to device.
Ad

Answer

It's most likely because you are adding both the Flutter Firebase dependencies as well as the native ones. You are not meant to add the native dependencies, as they will be added by the Flutter dependencies.

Try again after removing firebase-core, firebase-messaging and the design support dependencies from build.gradle.

Ad
source: stackoverflow.com
Ad