One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified
This issue has been resolved in version 4.3.0. The NativeMediaPlayer no longer relies on the legacy ExoPlayer. Instead, it now uses a customized media player to handle remote items.
2024-06-2918:09:11.1993101231012Error AndroidRuntime java.lang.SecurityException: com.glitch9.nativemediaplayer: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts2024-06-2918:09:11.1993101231012Error AndroidRuntime at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)2024-06-2918:09:11.1993101231012Error AndroidRuntime at android.os.Parcel.createException(Parcel.java:3041)2024-06-2918:09:11.1993101231012Error AndroidRuntime at android.os.Parcel.readException(Parcel.java:3024)2024-06-2918:09:11.1993101231012Error AndroidRuntime at android.os.Parcel.readException(Parcel.java:2966)2024-06-2918:09:11.1993101231012Error AndroidRuntime at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5713)2024-06-2918:09:11.1993101231012Error AndroidRuntime at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852)2024-06-2918:09:11.1993101231012Error AndroidRuntime at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792)2024-06-2918:09:11.1993101231012Error AndroidRuntime at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780)2024-06-2918:09:11.1993101231012Error AndroidRuntime at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755)2024-06-2918:09:11.1993101231012Error AndroidRuntime at com.google.android.exoplayer2.ui.PlayerNotificationManager.startOrUpdateNotification(PlayerNotificationManager.java:1165)2024-06-2918:09:11.1993101231012Error AndroidRuntime at com.google.android.exoplayer2.ui.PlayerNotificationManager.handleMessage(PlayerNotificationManager.java:1415)2024-06-2918:09:11.1993101231012Error AndroidRuntime at com.google.android.exoplayer2.ui.PlayerNotificationManager.$r8$lambda$hDN6RMWHvTCSAt_reWH1_HHmp5E(Unknown Source:0)2024-06-2918:09:11.1993101231012Error AndroidRuntime at com.google.android.exoplayer2.ui.PlayerNotificationManager$$ExternalSyntheticLambda0.handleMessage(Unknown Source:2)2024-06-2918:09:11.1993101231012Error AndroidRuntime at android.os.Handler.dispatchMessage(Handler.java:102)2024-06-2918:09:11.1993101231012Error AndroidRuntime at android.os.Looper.loopOnce(Looper.java:205)2024-06-2918:09:11.1993101231012Error AndroidRuntime at android.os.Looper.loop(Looper.java:294)2024-06-2918:09:11.1993101231012Error AndroidRuntime at android.app.ActivityThread.main(ActivityThread.java:8248)2024-06-2918:09:11.1993101231012Error AndroidRuntime at java.lang.reflect.Method.invoke(Native Method)2024-06-2918:09:11.1993101231012Error AndroidRuntime at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)2024-06-2918:09:11.1993101231012Error AndroidRuntime at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)2024-06-2918:09:11.1993101231012Error AndroidRuntime Caused by: android.os.RemoteException: Remote stack trace:2024-06-2918:09:11.1993101231012Error AndroidRuntime at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:14008)2024-06-2918:09:11.1993101231012Error AndroidRuntime at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2585)2024-06-2918:09:11.1993101231012Error AndroidRuntime at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2763)2024-06-2918:09:11.1993101231012Error AndroidRuntime at android.os.Binder.execTransactInternal(Binder.java:1358)2024-06-2918:09:11.1993101231012Error AndroidRuntime at android.os.Binder.execTransact(Binder.java:1304)2024-06-2918:09:11.1993101231012Error AndroidRuntime
Problem Description
When developing Android projects using ExoPlayer in Unity, you might encounter a java.lang.SecurityException related to broadcast receivers. This issue arises due to new requirements in Android 12 (API level 31) and above, which mandate specifying RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED when registering a receiver that is not exclusively for system broadcasts.
What You Might See
The application crashes with an error message stating:
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.
Root Cause
This crash is primarily due to an outdated version of ExoPlayer that does not expose the receiver registration process to the user, making it impossible to specify the required attributes. The issue is exacerbated by Unity's current lack of support for Java 17, which is necessary for migrating to Media3, the successor to ExoPlayer that supports these new requirements.
Workaround
The only feasible workaround, given the constraints, is to target SDK 33 in your project settings. This approach bypasses the need to comply with the stricter requirements introduced in SDK 34 and above, allowing you to continue using ExoPlayer without encountering the SecurityException.
By targeting SDK 33, you ensure compatibility with your existing setup in Unity and avoid the need for a more complex migration that is currently unsupported.