dart Flutter Firebase Messaging Crashing Targeting S+(版本31及以上)要求FLAG_IMMUTABLE之一

ghg1uchk  于 2023-05-04  发布在  Flutter
关注(0)|答案(3)|浏览(152)

最近,我们发布了Android应用程序目标31,其中报告了Firebase Messaging(PendingIntent)中的更多崩溃(仅限Android OS 12用户)。当应用程序在接收通知时处于暂停/后台状态时,它会崩溃。我已经尝试了可能的解决方案,但没有运气仍然崩溃。正如我所理解的,我们必须在PendingIntent启动活动上添加PendingIntent.FLAG_IMMUTABLE,但不知道如何添加或修复这个问题。
如果有人遇到同样的问题和固定。共享解决方案。
感谢您的评分

dependencies{
    implementation platform('com.google.firebase:firebase-bom')
    implementation 'com.google.firebase:firebase-messaging'
    implementation 'com.google.firebase:firebase-iid'
    implementation 'com.google.firebase:firebase-analytics:17.4.4'
    implementation 'com.google.firebase:firebase-crashlytics:17.0.0'
}
E/AndroidRuntime( 7058): java.lang.IllegalArgumentException: com.package: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
E/AndroidRuntime( 7058): Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
E/AndroidRuntime( 7058):    at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
E/AndroidRuntime( 7058):    at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458)
E/AndroidRuntime( 7058):    at android.app.PendingIntent.getActivity(PendingIntent.java:444)
E/AndroidRuntime( 7058):    at android.app.PendingIntent.getActivity(PendingIntent.java:408)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.CommonNotificationBuilder.createContentIntent(com.google.firebase:firebase-messaging@@20.3.0:125)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.CommonNotificationBuilder.createNotificationInfo(com.google.firebase:firebase-messaging@@20.3.0:27)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.CommonNotificationBuilder.createNotificationInfo(com.google.firebase:firebase-messaging@@20.3.0:9)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.DisplayNotification.handleNotification(com.google.firebase:firebase-messaging@@20.3.0:27)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(com.google.firebase:firebase-messaging@@20.3.0:65)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(com.google.firebase:firebase-messaging@@20.3.0:44)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(com.google.firebase:firebase-messaging@@20.3.0:27)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(com.google.firebase:firebase-messaging@@20.3.0:17)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService(com.google.firebase:firebase-messaging@@20.3.0:43)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.EnhancedIntentService$$Lambda$0.run(Unknown Source:6)
E/AndroidRuntime( 7058):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime( 7058):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime( 7058):    at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@17.6.0:2)
E/AndroidRuntime( 7058):    at java.lang.Thread.run(Thread.java:920)
W/CrashlyticsCore( 7058): Cannot send reports. Settings are unavailable.
D/TransportRuntime.SQLiteEventStore( 7058): Storing event with priority=HIGHEST, name=FIREBASE_CRASHLYTICS_REPORT for destination cct
xpcnnkqh

xpcnnkqh1#

我终于解决了。由于Firebase插件的较低版本而崩溃,在升级Android依赖项和Flutter插件后,它得到了解决。
步骤1:在android/app/build.gradle中

implementation 'com.google.firebase:firebase-messaging:20.1.5'

为了

implementation platform('com.google.firebase:firebase-bom') // add this 
implementation 'com.google.firebase:firebase-messaging:23.0.0'
implementation 'com.google.firebase:firebase-iid:21.1.0' // add this

步骤2:在Flutter pubspec.yaml中

firebase_core: ^0.5.0+1
firebase_messaging: ^7.0.3
firebase_remote_config: ^0.4.2
firebase_crashlytics: ^0.1.4+1
firebase_dynamic_links: ^0.6.3
firebase_auth: ^0.18.4+1

为了

firebase_core: ^1.10.0
firebase_messaging: ^11.2.6
firebase_remote_config: ^2.0.0
firebase_crashlytics: ^2.5.0
firebase_dynamic_links: ^4.0.5
firebase_auth: ^3.3.6
7hiiyaii

7hiiyaii2#

根据官方文档“如果您的应用面向Android 12,则必须指定应用创建的每个PendingIntent对象的可变性。此附加要求可提高应用的安全性。

Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);

   
PendingIntent contentIntent = PendingIntent.getActivity(context,NOTIFICATION_REQUEST_CODE, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);

我们正在构建一个标准类型的Intent,它将打开我们的应用,然后在将其添加到通知之前,简单地将其 Package 在PendingIntent中。在这种情况下,由于我们知道我们想要执行的确切操作,因此我们通过使用名为FLAG_IMMUTABLE的标志来构建一个PendingIntent,该PendingIntent不能被我们传递给它的应用修改。

zy1mlcev

zy1mlcev3#

更新com.google.firebase:firebase消息:

实现'com.google.firebase:firebase-messaging:20.1.5'

实现'com.google.firebase:firebase-messaging:23.0.0'
实现'com.google.firebase:firebase-iid:21.1.0'
和同步项目

相关问题