Android 14 giving RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts issue when playing a track
Describe the Bug Getting this error when i play a new audio in track player in Android 14 :
E FATAL EXCEPTION: main
Process: com.ishafoundation.app, PID: 23978
java.lang.SecurityException: com.ishafoundation.app: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
at android.os.Parcel.createExceptionOrNull(Parcel.java:3182)
at android.os.Parcel.createException(Parcel.java:3166)
at android.os.Parcel.readException(Parcel.java:3149)
at android.os.Parcel.readException(Parcel.java:3091)
at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5784)
at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1853)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1793)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1781)
at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:756)
at com.google.android.exoplayer2.ui.PlayerNotificationManager.startOrUpdateNotification(PlayerNotificationManager.java:1165)
at com.google.android.exoplayer2.ui.PlayerNotificationManager.handleMessage(PlayerNotificationManager.java:1415)
at com.google.android.exoplayer2.ui.PlayerNotificationManager.$r8$lambda$hDN6RMWHvTCSAt_reWH1_HHmp5E(Unknown Source:0)
at com.google.android.exoplayer2.ui.PlayerNotificationManager$$ExternalSyntheticLambda0.handleMessage(Unknown Source:2)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8501)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:14337)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2615)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2798)
at android.os.Binder.execTransactInternal(Binder.java:1496)
at android.os.Binder.execTransact(Binder.java:1440)
Code To Reproduce
try {
/**This throws an error if player setup has already been done before. */
await TrackPlayer.setupPlayer();
} catch (e) {
logError(e);
}
await TrackPlayer.updateOptions({
capabilities: [
Capability.Play,
Capability.Pause,
Capability.SkipToNext,
Capability.SkipToPrevious,
],
android: {
appKilledPlaybackBehavior:
AppKilledPlaybackBehavior.StopPlaybackAndRemoveNotification,
stopForegroundGracePeriod: 10,
},
});
/**
* Calling reset clears the full queue and stops current audio.
* This is done since our current use cases don't have any queue feature
*/
await TrackPlayer.reset();
await TrackPlayer.add([
{
url: audioSource,
title,
description,
artwork: imageSource,
album: '',
artist: '',
userAgent: `<my-custom-agent>`,
/// Added For resolving the audio not playing in iOS 17
pitchAlgorithm: PitchAlgorithm.Voice,
},
]);
Environment Info:
info Fetching system and libraries information...
System:
OS: macOS 14.2
CPU: (8) arm64 Apple M1 Pro
Memory: 91.28 MB / 16.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 18.19.0
path: ~/.nvm/versions/node/v18.19.0/bin/node
Yarn:
version: 3.6.4
path: ~/.nvm/versions/node/v18.19.0/bin/yarn
npm:
version: 10.2.3
path: ~/.nvm/versions/node/v18.19.0/bin/npm
Watchman:
version: 2024.01.22.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.15.2
path: /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 23.2
- iOS 17.2
- macOS 14.2
- tvOS 17.2
- watchOS 10.2
Android SDK:
API Levels:
- "26"
- "27"
- "28"
- "29"
- "30"
- "31"
- "33"
- "34"
Build Tools:
- 28.0.3
- 30.0.2
- 30.0.3
- 31.0.0
- 33.0.0
- 33.0.1
- 34.0.0
System Images:
- android-33 | Google APIs ARM 64 v8a
- android-34 | Google APIs ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: 2023.2 AI-232.10227.8.2321.11479570
Xcode:
version: 15.1/15C65
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.10
path: /usr/bin/javac
Ruby:
version: 2.7.6
path: /Users/natesh.bhat/.rbenv/shims/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.74.1
wanted: 0.74.1
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false
info React Native v0.74.2 is now available (your project is running on v0.74.1).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.74.2
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.74.1
info For more info, check out "https://reactnative.dev/docs/upgrading?os=macos".
Tried on Pixel 6 with Android 14
~u need to try to google first https://stackoverflow.com/questions/77235063/one-of-receiver-exported-or-receiver-not-exported-should-be-specified-when-a-rec afaik the example app/repo does not register a receiver? so unless u can pin point where a receiver is declared in this repo from a simple repo wide search, ur problem should lie somewhere else~
can u follow the error trace and find where PlayerNotificationManager is being called? is this the example app? without more info the only obvious "fix" is to migrate to media3
i followed the error trace and it gets called when it runs await TrackPlayer.add([
{
url: audioSource,
title,
description,
artwork: imageSource,
album: '',
artist: '',
userAgent: <my-custom-agent>,
/// Added For resolving the audio not playing in iOS 17
pitchAlgorithm: PitchAlgorithm.Voice,
},
]);
and then calls TrackPlayer.play() ;
are you able to reproduce this using the example app?
Are you using buildToolsVersion = "34.0.0"? I guess it's basically the same issue as this one.
Basically this new requirement forces you to pass a RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED value when registering a new receiver, e.g.: context.registerReceiver(broadcastReceiver, intentFilter, RECEIVER_NOT_EXPORTED);.
The problem is, the only registerReceivercall I can find in this repo is on a LocalBroadcastManager, which does not accept a third parameter. Unfortunately I am not familiar with kotlin and can't figure out the code responsible for the crash.
I hope one of the maintainers can have a look at this soon, also Google will force to use targetSdk 34 by the end of August, which, will brake this lib for all android users.
https://github.com/joltup/rn-fetch-blob/issues/866#issuecomment-2031638410 this is fixed here but after following the correct code the android app on Android 14 is still crashing anyone who knows the fix please help stuck from 2 days in this issue 😬
We are stuck here as well. Since Google is very pushy with Android 14, it would be great to get an update from the maintainers. Thanks in advance!
I got my issue solved https://github.com/joltup/rn-fetch-blob/issues/866#issuecomment-2031638410 check this I think that is the only issue with this fix I also removed flipper as it is recommended by react native to remove flipper for newer versions and I got my issue solved I think the crash was due to flipper in my case as the maintainer of the library fetch-blob has fixed this issue. I am using 0.73.8 version of react-native along with flipper removed hope this helps 🚀 👍
Solution: Update all instances of registerReceiver in the node_modules directory with the code below:
public void onActivityResumed(Activity activity) {
if (Build.VERSION.SDK_INT >= 34 && activity.getApplicationInfo().targetSdkVersion >= 34) {
Log.d("YourClassTag","API level is 34 or higher, and target SDK version is 34 or higher.");
activity.registerReceiver(reloadReceiver, new IntentFilter(RELOAD_BROADCAST), Context.RECEIVER_EXPORTED);
} else {
Log.d("YourClassTag","API level or target SDK version is lower than 34.");
activity.registerReceiver(reloadReceiver, new IntentFilter(RELOAD_BROADCAST));
}
}
Steps: Open the node_modules directory in your project. Find all instances of registerReceiver. Update each registerReceiver call as shown in the example above.
Detailed Example: Here is an example of how to update the registerReceiver call within the onActivityResumed method:
Old Code:
public void onActivityResumed(Activity activity) {
activity.registerReceiver(reloadReceiver, new IntentFilter(RELOAD_BROADCAST));
}
New Code:
public void onActivityResumed(Activity activity) {
if (Build.VERSION.SDK_INT >= 34 && activity.getApplicationInfo().targetSdkVersion >= 34) {
Log.d("YourClassTag", "API level is 34 or higher, and target SDK version is 34 or higher.");
activity.registerReceiver(reloadReceiver, new IntentFilter(RELOAD_BROADCAST), Context.RECEIVER_EXPORTED);
} else {
Log.d("YourClassTag", "API level or target SDK version is lower than 34.");
activity.registerReceiver(reloadReceiver, new IntentFilter(RELOAD_BROADCAST));
}
}
By making these updates, you can ensure compatibility with Android 14 and resolve issues related to registerReceiver usage.
Yes this works 🥳 issue was in JsDevReloadHandler.java file of react-native-navigation package that is fixed now my code is working fine please upgrade all the dependencies sorry the issue did not resolved after removing flipper just update react-native-navigation and it will be fixed 👍
Check this out https://github.com/wix/react-native-navigation/issues/7805#issuecomment-1804986640
why are yall reporting to the RNTP library while the issues are at eg react-native-navigation? am i missing anything? the only event receiver RNTP registers uses the deprecated LocalBroadcastManager but it still works just fine targeting sdk34. also FYI you SHOULD NOT modify node_modules by yourself other than patching it with patch-package or whatever yarnv2 does.
Was about to make patch-package but I think they have merged this fix in library itself so it is working fine no need to add patch-package 😅 @lovegaoshi
react-native-navigation+7.37.1-hotfix.1.patch Patch in case even if someone needs this 👍 🚀
We don't have any other package installed that registers any receiver only react-native-track-player and when trying to publish an application with Android 14 we also get the the same error. So, this is related somehow to this package. It is happening mainly on Google Pixel 5 64-bit only and Samsung Galaxy S23 Ultra when checked by Google Play Console. In the video we saw this, the application was forced to close immediately when it tried to start playing audio.
I cannot reproduce it unfortunately by using an emulator.
Can someone check it on a real device? Extend registerReceiver with Context.RECEIVER_EXPORTED is not possible as it does not support an argument like this.
can u reproduce with the example app on the devices u mentioned though? if not its ur repos issue, not RNTP. what i saw is nobody reproduces this error with the example app FYI my app targets sdk34, uses RNTP android auto fork, is on play store, I use daily on S21 and pixel 7 android 14, never saw this.
Is this happening somewhere in a dependency of react-native-track-player?
This is from our crash analytics system: java.lang.SecurityException: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
android.os.Parcel.createExceptionOrNull Parcel.java:3057 android.os.Parcel.createException Parcel.java:3041 android.os.Parcel.readException Parcel.java:3024 android.os.Parcel.readException Parcel.java:2966 android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature IActivityManager.java:5684 android.app.ContextImpl.registerReceiverInternal ContextImpl.java:1852 android.app.ContextImpl.registerReceiver ContextImpl.java:1792 android.app.ContextImpl.registerReceiver ContextImpl.java:1780 android.content.ContextWrapper.registerReceiver ContextWrapper.java:755 com.google.android.exoplayer2.ui.PlayerNotificationManager.startOrUpdateNotification PlayerNotificationManager.java:1165 com.google.android.exoplayer2.ui.PlayerNotificationManager.handleMessage PlayerNotificationManager.java:1415 com.google.android.exoplayer2.ui.PlayerNotificationManager.$r8$lambda$hDN6RMWHvTCSAt_reWH1_HHmp5E com.google.android.exoplayer2.ui.PlayerNotificationManager$$ExternalSyntheticLambda0.handleMessage android.os.Handler.dispatchMessage Handler.java:102 android.os.Looper.loopOnce Looper.java:205 android.os.Looper.loop Looper.java:294 android.app.ActivityThread.main ActivityThread.java:8177 java.lang.reflect.Method.invoke Method.java com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:552 com.android.internal.os.ZygoteInit.main ZygoteInit.java:971
I also use your Android Auto fork from the dev-android-auto branch, but my tests always give the same result when I upload a version to Google Play Console. Maybe it is happening because of a different version of react-native? In our application, we use version 0.72.5.
wdym test, what exactly is done? and like i said i dont see this error. unless u reproduce this in the example app its not going anywhere
On Fri, Jul 19, 2024, 12:32 PM Gábor Bajáki @.***> wrote:
I also use your Android Auto fork from the dev-android-auto branch, but my tests always give the same result when I upload a version to Google Play Console. Maybe it is happening because of a different version of react-native? In our application, we use version 0.72.5.
— Reply to this email directly, view it on GitHub https://github.com/doublesymmetry/react-native-track-player/issues/2327#issuecomment-2239985039, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZMOVVVDK7L5RNV7VOV5O3DZNFSVJAVCNFSM6AAAAABJLSRBSWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZZHE4DKMBTHE . You are receiving this because you commented.Message ID: @.*** com>
I mean Google Play Console automatic tests on several devices. All the test devices are having the same issue running Android 14 with our app with the same stack trace.
again i dont see this error so u really have to reproduce it with the example app
For those who face the same issue, please check the following solution: React Native - 41288
It is working fine with React Native 0.72.5.
org.jetbrains:annotations is not required if you don't use @Nullable annotation.
MainApplication.java
// Add imports
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import org.jetbrains.annotations.Nullable;
// ...
// Put this above "public void onCreate()":
@Override
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
if (Build.VERSION.SDK_INT >= 34 && getApplicationInfo().targetSdkVersion >= 34) {
return super.registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED);
} else {
return super.registerReceiver(receiver, filter);
}
}
// ....
With this, I have released my application successfully.
Also, don't forget to use the right build tools and SDK versions:
buildscript {
ext {
buildToolsVersion = "34.0.0"
minSdkVersion = 24
compileSdkVersion = 34
targetSdkVersion = 34
...
}
...
The example app targets SDK 33, so it's impossible to reproduce it, the example app needs to be updated to use SDK 34.
wdym test, what exactly is done? and like i said i dont see this error. unless u reproduce this in the example app its not going anywhere … On Fri, Jul 19, 2024, 12:32 PM Gábor Bajáki @.> wrote: I also use your Android Auto fork from the dev-android-auto branch, but my tests always give the same result when I upload a version to Google Play Console. Maybe it is happening because of a different version of react-native? In our application, we use version 0.72.5. — Reply to this email directly, view it on GitHub <#2327 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZMOVVVDK7L5RNV7VOV5O3DZNFSVJAVCNFSM6AAAAABJLSRBSWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZZHE4DKMBTHE . You are receiving this because you commented.Message ID: @. com>
I was facing this issue with version 4.0.0-rc04 of react-native-track-player. The player was crashing on android with the RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED error. However, after upgrading to 4.1.1 the issue is gone for me. For everyone who is experiencing this issue with the latest version (4.1.1), please double-check if it is caused by any other library that may cause the error, as suggested in the answers above (e.g. fetch-blob, navigation, etc.).
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.