Android app nowgetting "requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified" crash

fbs419 46 Reputation points
2025-02-25T19:51:44.0133333+00:00

I have a Visual Studio 2022 Xamarin Android app (I know it's now unsupported) that has worked fine for many years. It uses NuGet packages for Firebase, etc. After November 4 (probably the Firebase November 15 release), when the app is in the background and a notification comes in, it crashes with "FATAL EXCEPTION: Firebase-MyFirebaseMessagingService[AndroidRuntime] java.lang.IllegalArgumentException: requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.[AndroidRuntime]". I do already use Flag_Immutable in my PendingIntent calls, and like I said, this always worked fine. Upon much investigation, I figure I have to upgrade from Xamarin to .NET8. I am trying that, but I am having issues as to which NuGet packages to use so as not to cause compatibility problems. The packages in question are: Newtonsoft.Json, FirebaseMessaging, Xamarin.Android.Support (probably now AndroidX?), Xamarin.Essentials, Xamarin.AndroidX.LegacySupport, and Xamarin.GooglePlayServices. Main questions are:

  1. Is there a way to fix that error just within my current Xamarin project without having to migrate? I have tried many things, including adding AndroidX.Work.Runtime (which I can't because it's incomatible, etc.).
  2. If I do have to migrate, is there a list of the best packages to use for .NET8?
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,955 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 80,206 Reputation points Microsoft Vendor
    2025-02-26T07:23:53+00:00

    If I do have to migrate, is there a list of the best packages to use for .NET8?

    Firstly, you can read this MAUI support policy, check the different .NET version's end of support date.

    Then you can migrate to the specific .NET version.

    I create a .NET for android demo(.NET 9), And I install following nuget packages

    Microsoft.Maui.Essentials 9.0.40   Newtonsoft.Json 13.0.3   Xamarin.AndroidX.Legacy.Support.Core.Utils 1.0.0.31 and Xamarin.AndroidX.Work.Runtime 2.10.0.3 Xamarin.Firebase.Messaging 124.1.0.1, No compatibility problems. By the way some of Xamarin.GooglePlayServices have been added in the Xamarin.Firebase.Messaging 124.1.0.1.

    You can create a demo like us,then implement the basic function, if it works in your side. Then you can migrate to the .NET for android.

    If you have .net for android or migrated issue, you could select .NET tag and then select .NET MAUI child tag.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.