'In flutter app Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent

Please help me to sort out the problem. I give a link to the git. https://github.com/Vasajj/radio_tysa_fm.git something is wrong with PendingIntent, with package:flutter_radio_player On android 8 all is fine

Installing build\app\outputs\flutter-apk\app.apk...
Debug service listening on ws://127.0.0.1:55138/iMdUmbZTaNc=/ws
Syncing files to device sdk gphone64 x86 64...
I/javaClass(18284): Calling to method: initService
I/javaClass(18284): start service invoked
I/javaClass(18284): Attempting to initialize service...
I/javaClass(18284): Service not bound, binding now....
I/javaClass(18284): Mapping method call to player item object
I/javaClass(18284): Firing up service. (onStartCommand)...
I/javaClass(18284): LocalBroadCastManager Received...
W/e.radio_tysa_f(18284): Accessing hidden method Landroid/media/AudioTrack;->getLatency()I (unsupported, reflection, allowed)
I/ExoPlayerImpl(18284): Init 398a550 [ExoPlayerLib/2.13.1] [emulator64_x86_64_arm64, sdk_gphone64_x86_64, Google, 32]
I/javaClass(18284): Pushing Event: flutter_radio_loading
I/javaClass(18284): onPlayerStateChanged: LOADING
D/AndroidRuntime(18284): Shutting down VM
E/AndroidRuntime(18284): FATAL EXCEPTION: main
E/AndroidRuntime(18284): Process: com.example.radio_tysa_fm, PID: 18284
E/AndroidRuntime(18284): java.lang.RuntimeException: Unable to start service me.sithiramunasinghe.flutter.flutter_radio_player.core.StreamingCore@ed87b05 with Intent { cmp=com.example.radio_tysa_fm/me.sithiramunasinghe.flutter.flutter_radio_player.core.StreamingCore (has extras) }: java.lang.IllegalArgumentException: com.example.radio_tysa_fm: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
E/AndroidRuntime(18284): 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.
E/AndroidRuntime(18284):    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4697)
E/AndroidRuntime(18284):    at android.app.ActivityThread.access$2000(ActivityThread.java:256)
E/AndroidRuntime(18284):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2128)
E/AndroidRuntime(18284):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(18284):    at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime(18284):    at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime(18284):    at android.app.ActivityThread.main(ActivityThread.java:7842)
E/AndroidRuntime(18284):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(18284):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime(18284):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/AndroidRuntime(18284): Caused by: java.lang.IllegalArgumentException: com.example.radio_tysa_fm: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
E/AndroidRuntime(18284): 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.
E/AndroidRuntime(18284):    at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
E/AndroidRuntime(18284):    at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
E/AndroidRuntime(18284):    at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
E/AndroidRuntime(18284):    at com.google.android.exoplayer2.ui.PlayerNotificationManager.createBroadcastIntent(PlayerNotificationManager.java:1395)
E/AndroidRuntime(18284):    at com.google.android.exoplayer2.ui.PlayerNotificationManager.createPlaybackActions(PlayerNotificationManager.java:1351)
E/AndroidRuntime(18284):    at com.google.android.exoplayer2.ui.PlayerNotificationManager.<init>(PlayerNotificationManager.java:658)
E/AndroidRuntime(18284):    at com.google.android.exoplayer2.ui.PlayerNotificationManager.<init>(PlayerNotificationManager.java:568)
E/AndroidRuntime(18284):    at com.google.android.exoplayer2.ui.PlayerNotificationManager.createWithNotificationChannel(PlayerNotificationManager.java:521)
E/AndroidRuntime(18284):    at me.sithiramunasinghe.flutter.flutter_radio_player.core.StreamingCore.onStartCommand(StreamingCore.kt:248)
E/AndroidRuntime(18284):    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4679)
E/AndroidRuntime(18284):    ... 9 more
I/Process (18284): Sending signal. PID: 18284 SIG: 9
Lost connection to device.


Solution 1:[1]

The error message and stack trace tell you exactly what the problem is and where.

In com.google.android.exoplayer2.ui.PlayerNotificationManager.createBroadcastIntent(PlayerNotificationManager.java:1395)

you need to add either PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_MUTABLE to the call to PendingIntent.getBroadcast().

For more information see https://developer.android.com/guide/components/intents-filters#DeclareMutabilityPendingIntent

Solution 2:[2]

Add this to fix the problem: implementation 'androidx.work:work-runtime-ktx:2.8.0-alpha01'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Wasser
Solution 2 ahmed mohamed abdikadir