当前位置: 首页 > 知识库问答 >
问题:

颤动火力基础消息崩溃目标 S(版本 31 及更高版本)要求FLAG_IMMUTABLE

扈俊健
2023-03-14

最近,我们将Android应用程序目标发布到31,该目标报告了Firebase消息传递(待定意外)中更多的崩溃(仅限Android OS 12用户)。当应用程序在通知接收其崩溃时处于暂停/后台状态。我已经尝试了可能的解决方案,但没有运气仍然崩溃。据我所知,我们必须在“待定意外启动”活动上添加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

共有2个答案

濮阳宏硕
2023-03-14

根据官方文档“如果你的应用针对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,它将打开我们的应用程序,然后在将其添加到我们的notification.In之前简单地将其包装在PendingIntent中,因为我们知道我们想要执行一个确切的操作,我们构建了一个PendingIntent,该PendingIntent不能被我们通过使用名为FLAG_IMMUTABLE的标志传递给它的应用程序修改。

米俊喆
2023-03-14

我终于解决了这个问题。由于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

第二步:在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
 类似资料: