Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] crash with no logs - Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE #1484

Closed
okevino47 opened this issue Apr 21, 2022 · 16 comments

Comments

@okevino47
Copy link

okevino47 commented Apr 21, 2022

Describe the Bug
App crash (android only) when starting or reseting a playtrack, i do not have any logs affiliated to this crash and i only found some indication with flipper debugger

Before i update my sdk version from 30 to 31 and i was on lib version 2.1.2 i didn't get any crash

error given :
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.

FATAL EXCEPTION: main
Process: com.appname, PID: 15830
java.lang.RuntimeException: Unable to start service com.guichaguri.trackplayer.service.MusicService@8f5629a with Intent { cmp=com.appname/com.guichaguri.trackplayer.service.MusicService }: java.lang.IllegalArgumentException: com.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.
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5110)
at android.app.ActivityThread.access$2200(ActivityThread.java:310)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2319)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: java.lang.IllegalArgumentException: com.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.
at android.app.PendingIntent.checkFlags(PendingIntent.java:382)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:673)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:660)
at android.support.v4.media.session.MediaSessionCompat.(MediaSessionCompat.java:559)
at android.support.v4.media.session.MediaSessionCompat.(MediaSessionCompat.java:530)
at android.support.v4.media.session.MediaSessionCompat.(MediaSessionCompat.java:494)
at com.guichaguri.trackplayer.service.metadata.MetadataManager.(MetadataManager.java:62)
at com.guichaguri.trackplayer.service.MusicManager.(MusicManager.java:68)
at com.guichaguri.trackplayer.service.MusicService.onStartCommand(MusicService.java:108)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5092)
... 9 more

Steps To Reproduce
Use target and compileSdkVersion = 31 and set lib version to 2.1.3
after this call any function from TrackPlayerInstance

Code To Reproduce
Due to some complexe integration in my application (a mix between redux, sagas) i m not able to provide sample of code.

But this occur at any function call of "TrackPlayerInstance"

Environment Info:
System:
OS: macOS 12.3.1
CPU: (8) x64 Apple M1
Memory: 24.67 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.19.1 - ~/.nvm/versions/node/v14.19.1/bin/node
Yarn: 1.22.18 - ~/.nvm/versions/node/v14.19.1/bin/yarn
npm: 6.14.16 - ~/.nvm/versions/node/v14.19.1/bin/npm
Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK: Not Found
IDEs:
Android Studio: 2021.1 AI-211.7628.21.2111.8309675
Xcode: 13.3.1/13E500a - /usr/bin/xcodebuild
Languages:
Java: 11.0.11 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.67.4 => 0.67.4
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

"react-native-track-player": "2.1.3",
Real device - galaxy s10 + - android version 12

How I can Help
Actually i am looking for a solution and it seems to be a recognized error on some others libs with ancient / outdated libraries but i am actually not able to provide a patch

@okevino47 okevino47 added the Bug label Apr 21, 2022
@jspizziri
Copy link
Collaborator

@okevino47 can you please see if you have this issue with v2.2.0-rc3? There's a massive android rewrite underway and unless this is an issue there it likely won't be addressed.

@jspizziri
Copy link
Collaborator

Actually, after reading this it sounds like you're trying to upgrade to apiVersion 31. This is supported in the RC I mentioned, it's actually the minimum level. You can see this comment for more details

#1193 (comment)

@okevino47
Copy link
Author

Thank you for you quick answer 🙂
i tried with the version 2.2.0-rc3 and yeah that work.

Hope it will be release soon, good luck for your job 🙂

@MaxJadav
Copy link

For quick fix with old version 1.2.7

Step 1. Inside react-native-track-player -> build.gradle
Remove- implementation "androidx.media:media:1.1.0"
Add+ implementation "androidx.media:media:1.4.1"
Step 2. /node_modules/react-native-track-player/android/src/main/java/com/guichaguri/trackplayer/service/metadata/MetadataManager.java

Update
builder.setContentIntent(PendingIntent.getActivity(context, 0, openApp, PendingIntent.FLAG_CANCEL_CURRENT));
To
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
builder.setContentIntent(PendingIntent.getActivity(context, 0, openApp, PendingIntent.FLAG_IMMUTABLE));
}
else {
builder.setContentIntent(PendingIntent.getActivity(context, 0, openApp, PendingIntent.FLAG_CANCEL_CURRENT));
}

@gavrichards
Copy link
Contributor

This issue means we can't update our app to React Native 0.68. Is there likely to be a release soon?

@jspizziri
Copy link
Collaborator

@gavrichards Please see my comment

#1484 (comment)

@gavrichards
Copy link
Contributor

Thanks @jspizziri I've seen all the relevant comments, I just wondered if there's any news of when the next release is likely to be? Thanks

@jspizziri
Copy link
Collaborator

jspizziri commented May 8, 2022

@gavrichards The next RC? Or a final version of 2.2. The issue in question is solved in 2.2.0-rc3

@gavrichards
Copy link
Contributor

@jspizziri a release that contains a fix for this issue, whatever that happens to be :)

@jspizziri
Copy link
Collaborator

@gavrichards As I mentioned please install v2.2.0-rc3

@gavrichards
Copy link
Contributor

gavrichards commented May 9, 2022

@jspizziri ok I was concerned about using that in production in case it wasn't ready, and there's no changelog so I can understand what's new and any breaking changes.

@jspizziri
Copy link
Collaborator

jspizziri commented May 9, 2022

@gavrichards , there are known issues so I don't consider it production ready. Several fixes in the way. It's it's a minor version release meaning there should not be any BC breaks. If there are they would be considered bugs that would be fixed.

You can always look at the commit history since the last tag to see what's changed if you want. The big thing is the android rewrite.

@ProtoJoe
Copy link

For quick fix with old version 1.2.7

Step 1. Inside react-native-track-player -> build.gradle Remove- implementation "androidx.media:media:1.1.0" Add+ implementation "androidx.media:media:1.4.1" Step 2. /node_modules/react-native-track-player/android/src/main/java/com/guichaguri/trackplayer/service/metadata/MetadataManager.java

Update builder.setContentIntent(PendingIntent.getActivity(context, 0, openApp, PendingIntent.FLAG_CANCEL_CURRENT)); To if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { builder.setContentIntent(PendingIntent.getActivity(context, 0, openApp, PendingIntent.FLAG_IMMUTABLE)); } else { builder.setContentIntent(PendingIntent.getActivity(context, 0, openApp, PendingIntent.FLAG_CANCEL_CURRENT)); }

For anyone who is not in a position to update to 2.x, and needs to stay on 1.2.7 for a while, I've forked the repo at the 1.2.7 tag and made the changes suggested above. This works for me in my project, and I'm going to keep it live in my company's repo. Repo is here:

https://github.com/world50/react-native-track-player

Update your package.json like so:

"react-native-track-player": "^1.2.7", -> "react-native-track-player": "https://github.com/world50/react-native-track-player.git#8c042c8",

devpolo added a commit to devpolo/react-native-track-player that referenced this issue May 25, 2022
devpolo added a commit to devpolo/react-native-track-player that referenced this issue May 25, 2022
@devpolo devpolo mentioned this issue May 25, 2022
@MaxJadav
Copy link

@ProtoJoe
After fixing this FLAG_IMMUTABLE issue. Crashing in release mode, do you have any solution?
#1551 (comment)

mpivchev pushed a commit that referenced this issue Aug 2, 2022
* fix: Targeting S+ version 31 and above

source: #1484 (comment)

* fix: Targeting S+ version 31 and above 

source: #1484 (comment)

* chore: pump version
@ProtoJoe
Copy link

ProtoJoe commented Sep 8, 2022

@ProtoJoe After fixing this FLAG_IMMUTABLE issue. Crashing in release mode, do you have any solution? #1551 (comment)

Just catching up here. I haven't seen the issue referenced in that comment. We've been running w/ the updated form of the library since I patched it back in May, and it's been working well for us. I'll do a bit of digging and see if I see the same issues you've mentioned, but I don't believe we have.

@francowanseele
Copy link

francowanseele commented Apr 24, 2023

Hello! I don't want to update to version 3.x

This issue was solved in version 2.1.4 ??

Thanks :)


just editing comment.. with 2.1.4 seems like it was solved. I am not testing in production yet, only locally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants