Android 12 crash. Huawei services - android

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.

Related

how I can update SearchView?

I'm using createVoiceAppSearchIntent function from SearchView and this method still using PendingIntent.FLAG_ONE_SHOT and is crashing my app.
Causing 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.
There's something that I can do about?
Here is the log:
Fatal Exception: 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:382)
at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:465)
at android.app.PendingIntent.getActivity(PendingIntent.java:451)
at android.app.PendingIntent.getActivity(PendingIntent.java:415)
at androidx.appcompat.widget.SearchView.createVoiceAppSearchIntent(SearchView.java:1594)
at androidx.appcompat.widget.SearchView.onVoiceClicked(SearchView.java:1251)
at androidx.appcompat.widget.SearchView$5.onClick(SearchView.java:991)
at android.view.View.performClick(View.java:7792)
at android.view.View.performClickInternal(View.java:7769)
at android.view.View.access$3800(View.java:910)
at android.view.View$PerformClick.run(View.java:30218)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8669)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
This is due to update required for PendingIntent for apps targeting version 31 or above.
Try updating androidx.appcompat.widget
implementation "androidx.appcompat:appcompat:1.5.1"
Not sure what is the exact version that fixed this, but latest will do the work.

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;

Where do I put FLAG_IMMUTABLE or FLAG_MUTABLE for Android 12 head?

When I update my Xamarin Android head to compile using Android 12, and change the minimal version to 10.0 and the target to 12.0, I get the following exception when the application starts:
Java.Lang.IllegalArgumentException: '[Package Name]: 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.
The stacktrace is
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 androidx.work.impl.utils.ForceStopRunnable.getPendingIntent(ForceStopRunnable.java:196)
at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:128)
at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:93)
at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:920)
Now my project contains no such PendingIntent so I am wondering what I should do.
In this case adding the Xamarin.AndroidX.Work.Runtime NuGet package did the trick. In general this exception could mean a dependent package is not updated to support this Android 12 requirement.

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

App crashes because of pendingIntent when targeting to Android 12

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")

Categories

Resources