App crashes because of pendingIntent when targeting to Android 12 - android

App crashed because of Nearby message API when targeting to android 12.
Here is the crash log
2021-10-07 18:59:44.916 10343-10384/com.example.nearbymessagescanner E/AndroidRuntime: FATAL EXCEPTION: GoogleApiHandler
Process: com.example.nearbymessagescanner, PID: 10343
java.lang.IllegalArgumentException: com.example.nearbymessagescanner: 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 depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458)
at android.app.PendingIntent.getActivity(PendingIntent.java:444)
at android.app.PendingIntent.getActivity(PendingIntent.java:408)
at com.google.android.gms.common.api.GoogleApiActivity.zaa(com.google.android.gms:play-services-base##17.5.0:4)
at com.google.android.gms.common.GoogleApiAvailability.zaa(com.google.android.gms:play-services-base##17.5.0:116)
at com.google.android.gms.common.api.internal.GoogleApiManager.zaa(com.google.android.gms:play-services-base##17.5.0:252)
at com.google.android.gms.common.api.internal.GoogleApiManager$zaa.zaa(com.google.android.gms:play-services-base##17.5.0:109)
at com.google.android.gms.common.api.internal.GoogleApiManager$zaa.onConnectionFailed(com.google.android.gms:play-services-base##17.5.0:75)
at com.google.android.gms.common.internal.zai.onConnectionFailed(com.google.android.gms:play-services-base##17.5.0:2)
at com.google.android.gms.common.internal.BaseGmsClient$zzf.zza(com.google.android.gms:play-services-basement##17.5.0:6)
at com.google.android.gms.common.internal.BaseGmsClient$zza.zza(com.google.android.gms:play-services-basement##17.5.0:21)
at com.google.android.gms.common.internal.BaseGmsClient$zzc.zzc(com.google.android.gms:play-services-basement##17.5.0:11)
at com.google.android.gms.common.internal.BaseGmsClient$zzb.handleMessage(com.google.android.gms:play-services-basement##17.5.0:49)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.os.HandlerThread.run(HandlerThread.java:67)
This exception happens even I added the flag PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_IMMUTABLE for the pendingIntent
private fun backgroundSubscribe() {
Log.d(TAG, "Subscribing for background updates.")
val options = SubscribeOptions.Builder().setStrategy(Strategy.BLE_ONLY).build()
messagesClient.subscribe(pendingIntent, options)
}
private val pendingIntent: PendingIntent
get() = PendingIntent.getBroadcast(
this,
0,
Intent(this, BeaconMessageReceiver::class.java),
PendingIntent.FLAG_MUTABLE
)
This is a sample app that can reproduce this issue by clicking subscribe button in the app.
I am using the version 18.0.0 of play-services-nearby
implementation 'com.google.android.gms:play-services-nearby:18.0.0'

It sounds strange, but the fix is adding work manager dependency 2.7.0+ : implementation "androidx.work:work-runtime:2.7.0"
You have to update dependencies that should support Android 12 braking changes (I had to update some third parties). Check that on github and documentation pages
Also, some libraries are using permission <uses-permission android:name="com.google.android.gms.permission.AD_ID"/> that is required for Android 12. Please check the documentation for this permission
Also, check google's issue tracker for google's library-specific issues related to Android 12
Maybe I missed something, but all this helped me to migrate. Good luck :)

Installing Xamarin.AndroidX.work.runtime 2.7.0 resolved the issue for me. Please make sure you have the right version so you don't run into some problems as I did. Happy codding!!

I was able to resolve this issue for a Xamarin project by adding the Xamarin.AndroidX.work.runtime NuGet package.

Updating the dependency alone should fix the issue. 18.1.0+ seems to fix this (looking at decompiled code) and 17.0.0 does not. (Not sure about the versions in between.)
implementation("com.google.android.gms:play-services-base:18.1.0")

Related

How to declare firebase pending intent as immutable in xamarin android?

I have added firebase nuget for FirebaseInstanceIdService, FirebaseMessagingService to implement notification.
if target version is 12 or above 12 then throwing exception:
Java.Lang.IllegalArgumentException: 'com.testapp: 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 depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.'
but if target version is 11 or under 11 then push notification is working using firebase and no such exception.
code is as:
can anyone help?
Please try to update the options below:
1.updated android sdk ;
2.update firebase library and other nugets to the latest one;
3.try to change the compile and target versions to the newer one in manifest file;

App crashes : Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent

After updating targetsdk version to 31, the app is giving an error on pending intents. I have updated all the pending intents and then run the app. But the app is now crashing with this error
Caused by: java.lang.IllegalArgumentException: fm.iono.p953: 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 depends on the PendingIntent being mutable, e.g. if
it needs to be used with inline replies or bubbles.
But the line that the app crashes is the following:
val gmsTracker = GoogleAnalytics.getInstance(context).newTracker(gmsId)
see the screenshot below. I have highlighted the line with blue color where the app crashes. And from the logcat you can see the error. Not sure why the app is crashing on the line where no pending intent is available :)
Any help will be appreciated
Make sure you are on the latest version of the Google Analytics dependency. It apparently is setting up that PendingIntent, and only the developers of Google Analytics can change that behavior.

CRASH on Android 12 while using Huawei app service dependency, with build tools 31

We have implementation of
"com.huawei.hms:appservice:$huaweiAppService" WHERE huaweiAppService = '6.1.0.301'
And there is a crash:
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 depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458)
at android.app.PendingIntent.getActivity(PendingIntent.java:444)
at android.app.PendingIntent.getActivity(PendingIntent.java:408)
at com.huawei.hms.api.b.getErrPendingIntent(HuaweiApiAvailabilityImpl.java:10)
at com.huawei.hms.common.internal.BaseHmsClient.resolution(BaseHmsClient.java:3)
at com.huawei.hms.common.internal.BaseHmsClient.checkAvailabilityAndConnect(BaseHmsClient.java:34)
at com.huawei.hms.common.internal.BaseHmsClient.connect(BaseHmsClient.java:1)
at com.huawei.hms.common.internal.HuaweiApiManager$ConnectionManager.connect(HuaweiApiManager.java:21)
at com.huawei.hms.common.internal.HuaweiApiManager$ConnectionManager.sendRequest(HuaweiApiManager.java:24)
at com.huawei.hms.common.internal.HuaweiApiManager.connectAndSendRequest(HuaweiApiManager.java:8)
at com.huawei.hms.common.internal.HuaweiApiManager.handleMessage(HuaweiApiManager.java:7)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.os.HandlerThread.run(HandlerThread.java:67)
I noticed that some Huawei services already have updates related with issue. So I'm asking about appservice.
Thank you for your feedback, this issue is a known issue. The R&D team will release a new fixed version in mid-November, and I'll update this answer and let you know when it's released.
Problem temporary solved by adding huaweiBase transition dependency along with appService dependency.
It's updated some source of appServiceLibrary under the hood and it's looks like temporary fix. In near future I will remove this base dependency and just updated appService to newer.
huaweiBase = '6.2.0.300'
huaweiAppService = '6.1.0.301'
huaweiDependencies = [
huaweiBase: "com.huawei.hms:base:$huaweiBase",
appService: "com.huawei.hms:appservice:$huaweiAppService"
]
implementation huaweiDependencies.huaweiBase
implementation huaweiDependencies.appService

Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent, On AlarmPingSender

Problem
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. I got it after updating target SDK to 31. the error always come after AlarmPingSender. But i dont know any class that used AlarmPingSender.
2021-10-31 10:43:04.990 17031-17341/com.app.mobile D/AlarmPingSender: Register alarmreceiver to MqttServiceMqttService.pingSender.com.app.mobile-2e24ccbde048f2e91635651784
2021-10-31 10:43:04.993 17031-17341/com.app.mobile E/AndroidRuntime: FATAL EXCEPTION: MQTT Rec: com.app.mobile-2e24ccbde048f2e91635651784
Process: com.app.mobile, PID: 17031
java.lang.IllegalArgumentException: com.app.mobile: 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 depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
at org.eclipse.paho.android.service.AlarmPingSender.start(AlarmPingSender.java:76)
at org.eclipse.paho.client.mqttv3.internal.ClientState.connected(ClientState.java:1150)
at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:987)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:118)
at java.lang.Thread.run(Thread.java:920)
What I Already done
Upgrade WorkManager to 2.7.0
set AllProject to force use WorkManager to 2.7.0
change all existing PendingIntent to use FLAG_IMMUTABLE
there's old code that still use gcm and disable it
Updating all Firebase package (some said its because of later version of analytics)
Library Used
OneSignal
Qiscus
Firebase
WorkManager
Add the following to your build.gradle(app) dependencies.
dependencies {
// For Java
implementation 'androidx.work:work-runtime:2.7.1'
// For Kotlin
implementation 'androidx.work:work-runtime-ktx:2.7.1'
}
Possible solution
Upgrade google analytics to firebase analaytics. Hope it'll solve your problems.Also upgrade all the library what're you using.
For me below solutions solve the problem.
Add PendingIntent.FLAG_IMMUTABLE to your pending intents.
Here is an example -
PendingIntent pendingIntent = PendingIntent.getActivity(this, alarmID, notificationIntent, PendingIntent.FLAG_IMMUTABLE);
For further information follow this link -
https://developer.android.com/reference/android/app/PendingIntent#FLAG_IMMUTABLE
I had this crash but no 3rd party libraries. Adding this import with the latest version will fix the crash.
implementation 'androidx.work:work-runtime-ktx:2.7.0-beta01'
in addition to others' answers I changed :
implementation 'com.google.firebase:firebase-messaging:20.0.0'
to :
implementation 'com.google.firebase:firebase-messaging:23.0.0'
and its working now.
After several attempt to fix this, i gave up and try to contact Qiscus. And they release new version that handle this Pending Intent behaviour change. So if anyone use Qiscus and got this error, you can use latest tag
https://github.com/qiscus/qiscus-sdk-android/releases/tag/1.3.35
If you use the WorkManager in your project, update it to the latest. If you don't, update all you firebase libraries and google libraries to the latest. I faced with the same problem and I was updating libraries one by one. And I found that updating com.google.android.gms:play-services-ads to the latest solved the problem
required to avoid crash on Android 12 API 31
implementation 'androidx.work:work-runtime-ktx:2.7.1'
It may be one of them according to the answers of others. Or by removing this library:
implementation 'androidx.hilt:hilt-work:1.0.0'

Android 12 crash. Huawei services

In our app we have dependency: com.huawei.hms:base:6.1.0.302 and use HuaweiApiAvailability class.
As result of calling this function PendingIntent getErrPendingIntent(Context var1, ConnectionResult var2) we have exception:
Process: com...preview, PID: 10355
java.lang.IllegalArgumentException: com...preview: 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 depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458)
at android.app.PendingIntent.getActivity(PendingIntent.java:444)
at android.app.PendingIntent.getActivity(PendingIntent.java:408)
at com.huawei.hms.api.b.getErrPendingIntent(HuaweiApiAvailabilityImpl.java:10)
at com.huawei.hms.common.internal.BaseHmsClient.resolution(BaseHmsClient.java:3)
at com.huawei.hms.common.internal.BaseHmsClient.checkAvailabilityAndConnect(BaseHmsClient.java:34)
at com.huawei.hms.common.internal.BaseHmsClient.connect(BaseHmsClient.java:1)
at com.huawei.hms.common.internal.HuaweiApiManager$ConnectionManager.connect(HuaweiApiManager.java:21)
at com.huawei.hms.common.internal.HuaweiApiManager$ConnectionManager.sendRequest(HuaweiApiManager.java:24)
at com.huawei.hms.common.internal.HuaweiApiManager.connectAndSendRequest(HuaweiApiManager.java:8)
at com.huawei.hms.common.internal.HuaweiApiManager.handleMessage(HuaweiApiManager.java:7)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
Question: are you planning to update PendingIntens with new flag for Android 12?
Update
A new version of the base SDK has been released :
implementation 'com.huawei.hms:base:6.2.0.300'
This issue has been fixed, you can explicitly depend on this version of base sdk first, which should fix the problem.
Thank you for your feedback, the R&D team confirms that a fixed version will be released at the end of September.
Please use the latest version for testing by that time. Thanks.

Categories

Resources