Firebase Cloud Messaging Unity SDK targeting Android 12 and up crashes

I am using Firebase Cloud Messaging in my app. Regardless of which Unity version I use (2020.3.7.f1, 2021.3.3f1, 2021.3.8f1) after setting the target API to 31 (Required by November 1st 2022 for existing apps) the app will immediately be forced to shut down on start by the OS. From my understanding, this is due to a dependency for cloud messaging not having a FLAG_IMMUTABLE condition set. I don’t know if this is a google related issue or an issue with OpenJDK, but anyone who wants their app to appear in the play store after November 1st 2022 needs this fixed if they intend to use Firebase Cloud Messaging.

@ is this due to the Open JDK included with Unity install not being up to date to comply with the recent Android play store requirements? I don’t know how to fix this issue. I have tried to use versions 9.4.0, v9.3.0, v9.2.0 Unity SDK for firebase messaging but all have the same issue.

Exact error appears in android studio log when attempting to run the app:

 FATAL EXCEPTION: pool-15-thread-1
    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.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)

Related issue:

Updating the main template gradle file with the constraint for the androidx.work dependency to target 2.7.0 works. However the External dependency manager’s android resolver will include both 2.4.0 and 2.7.0 in the gradle file. For our project I also needed to include the gradle launcher and properties files with the build as well otherwise Unity couldn’t resolve or build.

I followed the example provided in the google release notes.