I have been working with Flutter for a year now but its my first time with push notifications. I am trying to add push notifications in an old project. I have wrote the cloud firebase functions to push the notifications from.
But when the notification is sent to the token of the android phone. The android app crashes with the following error message.
2021-01-13 00:49:37.011 6127-6127/com.app.oldProject E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.oldProject, PID: 6127
java.lang.RuntimeException: Unable to instantiate receiver com.google.firebase.iid.FirebaseInstanceIdReceiver: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceIdReceiver" on path: DexPathList[[zip file "/data/app/com.app.oldProject-wnxma3Smq-VCUX1eO04_kg==/base.apk"],nativeLibraryDirectories=[/data/app/com.app.oldProject-wnxma3Smq-VCUX1eO04_kg==/lib/arm64, /data/app/com.app.oldProject-wnxma3Smq-VCUX1eO04_kg==/base.apk!/lib/arm64-v8a, /system/lib64]]
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3633)
at android.app.ActivityThread.access$1400(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1889)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7081)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:928)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceIdReceiver" on path: DexPathList[[zip file "/data/app/com.app.oldProject-wnxma3Smq-VCUX1eO04_kg==/base.apk"],nativeLibraryDirectories=[/data/app/com.app.oldProject-wnxma3Smq-VCUX1eO04_kg==/lib/arm64, /data/app/com.app.oldProject-wnxma3Smq-VCUX1eO04_kg==/base.apk!/lib/arm64-v8a, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateReceiver(AppComponentFactory.java:84)
at androidx.core.app.CoreComponentFactory.instantiateReceiver(CoreComponentFactory.java:60)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3626)
at android.app.ActivityThread.access$1400(ActivityThread.java:237)?
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1889)?
at android.os.Handler.dispatchMessage(Handler.java:106)?
at android.os.Looper.loop(Looper.java:224)?
at android.app.ActivityThread.main(ActivityThread.java:7081)?
at java.lang.reflect.Method.invoke(Native Method)?
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)?
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:928)?
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/legacy/content/WakefulBroadcastReceiver;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
... 12 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.legacy.content.WakefulBroadcastReceiver" on path: DexPathList[[zip file "/data/app/com.app.oldProject-wnxma3Smq-VCUX1eO04_kg==/base.apk"],nativeLibraryDirectories=[/data/app/com.app.oldProject-wnxma3Smq-VCUX1eO04_kg==/lib/arm64, /data/app/com.app.oldProject-wnxma3Smq-VCUX1eO04_kg==/base.apk!/lib/arm64-v8a, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 15 more
I am sharing the pubspec.yaml and gradles below for my project so you can see the dependencies.
pubspec.yaml:
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.9.7+2
firebase_storage: ^2.1.0+1
firebase_core: ^0.3.0
image_cropper: ^1.2.3
firebase_auth: ^0.8.3
image: ^2.0.7
cupertino_icons: ^1.0.0
path_provider: ^1.6.21
firebase_messaging: ^4.0.0+1
these are the dependencies in appuild.gradle
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.firebase:firebase-core:16.0.1'
}
my flutter code is
configurePushNotifications() {
_firebaseMessaging.getToken().then((token) {
print("Firebase Messaging Token: $token
");
usersRef.document(currentUser.id).updateData({"token": token});
});
_firebaseMessaging.configure(
onLaunch: (Map<String, dynamic> message) async {
print("here in the on Launch");
},
onResume: (Map<String, dynamic> message) async {
print("here in the on Resume ");
},
onMessage: (Map<String, dynamic> message) async {
print("on message: $message
");
},
);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…