Xamarin Forms: Portable: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE when creating a PendingIntent

Sreejith Sreenivasan 691 Reputation points
2024-04-19T04:31:05.6933333+00:00

I am facing below issue when I updated the target platform of the Android to 34.

Java.Lang.IllegalArgumentException: 'com.companyname.appname: 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.'

I already faced this same issue on .Net standard Xamarin Forms Project and I have resolved it by this thread. As per the thread I have added Xamarin.AndroidX.work.runtime 2.7.1.5, updated all the Firebase Packages to latest and set the PendingIntentFlags to Mutable like below.

var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.Mutable);

But now I am facing the same issue on a Portable Xamarin Forms Project and the same solution mentioned above is not working.

When I install the Xamarin.AndroidX.Work.Runtime 2.9.0.1 I am getting the below error:

Could not install package 'Xamarin.AndroidX.Work.Runtime 2.9.0.1'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v11.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

When I try to update the Firebase Packages to latest I am getting the below error.

Could not install package 'Xamarin.Firebase.Iid 121.1.0.7'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v11.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

And when setting the PendingIntentFlags, the Mutable flag is not available. Available flag screenshot adding below:

User's image

Is there any other solution to fix this issue for Portable Xamarin Forms project? We have started the MAUI Migration for this project but it takes time, but I need to push it to stores immediately with version changes.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,294 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sreejith Sreenivasan 691 Reputation points
    2024-04-22T09:11:41.16+00:00

    The versions I mentioned are not supported for the MonoAndroid,Version=v11.0, so I updated project's MonoAndroid version to version v13.0.

    Right click on the Project.Android -> Properties -> Set the Compile using Android Version:

    enter image description here

    And then I can update the two packages and the Mutable flag is also available.