8

Ive seen this issue a few times now, but never for xamarin.forms:

When I am trying to deploy on android 12 I am getting:

com.interiorcircle.interiorcircledroid: 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.

Here in picture: enter image description here

Appearently, a flag needs to be set, but I cannot figure out where.

Anyone has some help here?

innom
  • 770
  • 4
  • 19
  • I was able to resolve this issue for a Xamarin project by adding the [Xamarin.AndroidX.work.runtime](https://www.nuget.org/packages/Xamarin.AndroidX.Work.Runtime/) NuGet package. – Alperen Kuru Dec 15 '22 at 17:24
  • 1
    Install the Xamarin.AndroidX.work.runtime to remove error. See link below. See the following [https://stackoverflow.com/a/70157415/6902149](https://stackoverflow.com/a/70157415/6902149) – Blackie Feb 15 '22 at 16:15
  • I tried that. Upon installing the latest versin from xamarin.androidX.work however the app issnt able to install those packages. – innom Feb 16 '22 at 14:47

3 Answers3

6

In my case following code has fixed the runtime error:

var pendingIntentFlags = (Build.VERSION.SdkInt >= BuildVersionCodes.S)
                ? PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable
                : PendingIntentFlags.UpdateCurrent;
var pendingActivityIntent = PendingIntent.GetActivity(Application.Context, requestCode, activityIntent, pendingIntentFlags);
var pendingIntent = PendingIntent.GetBroadcast(Application.Context, requestCode, intent, pendingIntentFlags);
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Adil Dawut
  • 61
  • 1
  • 2
2

If you cannot figure out where then you probably don't use PendingIntent in your code.

In that case it means that some of the packages that you use is using this code and they need to fix it. Possibly you need to report the problem to them if they are not already aware of it.

Ivan Ičin
  • 9,672
  • 5
  • 36
  • 57
  • That's true , the solution is to search the alternative or change target framework (down to Android 11). – ColeX Feb 10 '22 at 06:02
  • how do i find the package in question? The stack trace does not seem to deliever useful information ... – innom Feb 10 '22 at 11:41
  • @innom if this is happening while you perform something then you probably know which package you use in that method. If there is more than one candidate then you'll need to refactor the code till you figure out which one is the problem. – Ivan Ičin Feb 10 '22 at 11:48
  • Did you follow the steps : https://stackoverflow.com/a/69754721/8187800? – ColeX Feb 18 '22 at 07:31
1

It was resolved by updating the nuget (Xamarin.AndroidX.Work.Runtime ) with the most current version in the Android project.

https://www.nuget.org/packages/Xamarin.AndroidX.Work.Runtime/