marcojak / MTAdmob

Admob plugin for Xamarin Android and iOS
https://www.xamarinexpert.it/admob-made-easy/
160 stars 26 forks source link

Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE #106

Closed douglassimaodev closed 1 year ago

douglassimaodev commented 2 years ago

I installed the latest version and I am getting the following error:

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.

douglassimaodev commented 2 years ago

Ok so I am not sure what this will impact when publishing and installed in android 12+ but if you right click android project and go to Properties and change Application -> Compile using android version: from 12+ to 11.0 (R) and in Android Manifest -> Target Android version from 12+ to 11.0 (api Level 30 - R) error is sorted

arahmancsd commented 1 year ago

These steps worked for me. I used BroadcastReceiver and PendingIntent in my project so I changed them to

[BroadcastReceiver(Enabled = true, Label = "Local Notifications Broadcast Receiver", Exported = true)] for pending intent

var pendingIntentFlags = (Build.VERSION.SdkInt >= BuildVersionCodes.S)
                ? PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable
                : PendingIntentFlags.UpdateCurrent;
var pendingIntent = PendingIntent.GetBroadcast(AndroidApp.Context, code, intent, pendingIntentFlags);

and finally installed Xamarin.AndroidX.Work.Runtime 2.7.0

marcojak commented 1 year ago

As @arahmancsd said, the trick is to update Xamarin.AndroidX.Work.Runtime to 2.7.0.

I'm going to update the sample project to show that. For now I'll close the issue but feel free to re-open it if needed

N1koV373z commented 1 year ago

These steps worked for me. I used BroadcastReceiver and PendingIntent in my project so I changed them to

[BroadcastReceiver(Enabled = true, Label = "Local Notifications Broadcast Receiver", Exported = true)] for pending intent

var pendingIntentFlags = (Build.VERSION.SdkInt >= BuildVersionCodes.S)
                ? PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable
                : PendingIntentFlags.UpdateCurrent;
var pendingIntent = PendingIntent.GetBroadcast(AndroidApp.Context, code, intent, pendingIntentFlags);

and finally installed Xamarin.AndroidX.Work.Runtime 2.7.0

can you please explain for a newbie how and where to do it exactly?

arahmancsd commented 1 year ago

These steps worked for me. I used BroadcastReceiver and PendingIntent in my project so I changed them to [BroadcastReceiver(Enabled = true, Label = "Local Notifications Broadcast Receiver", Exported = true)] for pending intent

var pendingIntentFlags = (Build.VERSION.SdkInt >= BuildVersionCodes.S)
                ? PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable
                : PendingIntentFlags.UpdateCurrent;
var pendingIntent = PendingIntent.GetBroadcast(AndroidApp.Context, code, intent, pendingIntentFlags);

and finally installed Xamarin.AndroidX.Work.Runtime 2.7.0

can you please explain for a newbie how and where to do it exactly?

You can do this in your Platform project (Android) where you have used PendingIntentsFlags.