我想通過 firebase 發送通知。當我發送通知時,我的應用程序崩潰,在 logcat 中顯示這種類型的堆棧跟蹤: 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 "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.example.e_agriculture10-1.apk", zip file "/data/data/com.example.e_agriculture10/code_cache/secondary-dexes/com.example.e_agriculture10-1.apk.classes2.zip"],nativeLibraryDirectories=[/data/app-lib/com.example.e_agriculture10-1, /system/lib]] at android.app.ActivityThread.handleReceiver(ActivityThread.java:2398) at android.app.ActivityThread.access$1700(ActivityThread.java:135) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceIdReceiver" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.example.e_agriculture10-1.apk", zip file "/data/data/com.example.e_agriculture10/code_cache/secondary-dexes/com.example.e_agriculture10-1.apk.classes2.zip"],nativeLibraryDirectories=[/data/app-lib/com.example.e_agriculture10-1, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:497)這是我的 FirebaseMessagingService.java 類public class MyFirebaseMessagingService extends FirebaseMessagingService {public static int NOTIFICATION_ID = 1;@Overridepublic void onMessageReceived(RemoteMessage remoteMessage) { generateNotification(remoteMessage.getNotification().getBody(),remoteMessage.getNotification().getTitle());}
2 回答

皈依舞
TA貢獻1851條經驗 獲得超3個贊
您可以刪除此類“GettingDeviceTokenService”并覆蓋“MyFirebaseMessagingService”類中的“onNewToken”方法。
public void onNewToken(@NonNull String your_new_token) {super.onNewToken(s);}
用你的新令牌做你想做的事

慕絲7291255
TA貢獻1859條經驗 獲得超6個贊
與 unownsp 的答案一起,如果您使用 proguard,這可能會有所幫助;將這些添加到您的 proguard 配置文件中:
-dontwarn com.google.android.gms.** -keep class com.google.android.gms.** { *; } -keep class com.google.firebase.** { *; }
添加回答
舉報
0/150
提交
取消