崩溃的应用程序是一个遗留应用程序,仍在使用 GCM 进行通知,没有任何支持,但是当我将应用程序升级到 Target sdk api 33 时,它开始在 Android api 31 或更高版本的手机中崩溃,并开始抛出以下异常:
java.lang.IllegalArgumentException:
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depenat android.app.PendingIntent.checkPendingIntent(PendingIntent.java:428)
at android.app.PendingIntent.checkPendingIntent(PendingIntent.java:428)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:731)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:718)
at com.google.android.gms.iid.zzl.zzi(Unknown Source:18)
at com.google.android.gms.iid.zzl.zzb(Unknown Source:224)
at com.google.android.gms.iid.zzl.zza(Unknown Source:0)
at com.google.android.gms.iid.InstanceID.zzb(Unknown Source:60)
at com.google.android.gms.iid.InstanceID.getToken(Unknown Source:120)
当我调试时,我发现应用程序在以下行崩溃:
regid = instanceID.getToken(SENDER_ID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
没有将 GCM 更新到 Firebase 的选项,因为这需要大量的努力和资源。
您必须将 Firebase Messaging sdk 版本更新到最新版本 目前最新版本是23.3.1