我想将通知从FCM发送到我的设备,但是每次发送通知时,我的应用始终停止运行。可能是什么问题?
这是我的一些代码
// 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'
}
//项目级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:
错误日志:
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.
答案 0 :(得分:1)
最可能是因为您同时添加了Flutter Firebase依赖项和本机依赖项。您无意添加本机依赖项,因为它们将由Flutter依赖项添加。
从build.gradle中删除firebase-core,firebase-messaging和设计支持依赖项后重试。