One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
ThushalIntervest opened this issue Β· comments
Steps to reproduce
- In Android 14(SDK 34) share function is not working
Expected behavior
it should work as previous android versions
Actual behavior
App crash when call the Share.open
Environment
- React Native version: 0.72.4
- React Native platform + platform version: Android 14.0 beta
react-native-share
Version: 9.4.1
One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
2023-09-13 15:07:08.027 16203-17052 System.out com.test.app I java.lang.SecurityException: com.test.app: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
2023-09-13 15:07:08.027 16203-17052 System.out com.test.app I at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
2023-09-13 15:07:08.027 16203-17052 System.out com.test.app I at android.os.Parcel.createException(Parcel.java:3041)
2023-09-13 15:07:08.027 16203-17052 System.out com.test.app I at android.os.Parcel.readException(Parcel.java:3024)
2023-09-13 15:07:08.027 16203-17052 System.out com.test.app I at android.os.Parcel.readException(Parcel.java:2966)
2023-09-13 15:07:08.027 16203-17052 System.out com.test.app I at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5684)
2023-09-13 15:07:08.027 16203-17052 System.out com.test.app I at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852)
2023-09-13 15:07:08.028 16203-17052 System.out com.test.app I at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792)
2023-09-13 15:07:08.028 16203-17052 System.out com.test.app I at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780)
2023-09-13 15:07:08.028 16203-17052 System.out com.test.app I at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755)
2023-09-13 15:07:08.028 16203-17052 System.out com.test.app I at cl.json.social.TargetChosenReceiver.getSharingSenderIntent(TargetChosenReceiver.java:49)
2023-09-13 15:07:08.028 16203-17052 System.out com.test.app I at cl.json.social.ShareIntent.openIntentChooser(ShareIntent.java:268)
2023-09-13 15:07:08.028 16203-17052 System.out com.test.app I at cl.json.social.GenericShare.open(GenericShare.java:20)
2023-09-13 15:07:08.028 16203-17052 System.out com.test.app I at cl.json.RNShareImpl.open(RNShareImpl.java:158)
2023-09-13 15:07:08.028 16203-17052 System.out com.test.app I at cl.json.RNShare.open(RNShare.java:35)
2023-09-13 15:07:08.028 16203-17052 System.out com.test.app I at java.lang.reflect.Method.invoke(Native Method)
2023-09-13 15:07:08.029 16203-17052 System.out com.test.app I at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
2023-09-13 15:07:08.029 16203-17052 System.out com.test.app I at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
Android 14 need to specify the receiver. You need to patch the lib:
diff --git a/node_modules/react-native-orientation-locker/android/src/main/java/org/wonday/orientation/OrientationModule.java b/node_modules/react-native-orientation-locker/android/src/main/java/org/wonday/orientation/OrientationModule.java
index 4a44ff6..3916d49 100644
--- a/node_modules/react-native-orientation-locker/android/src/main/java/org/wonday/orientation/OrientationModule.java
+++ b/node_modules/react-native-orientation-locker/android/src/main/java/org/wonday/orientation/OrientationModule.java
@@ -353,7 +353,7 @@ public class OrientationModule extends ReactContextBaseJavaModule implements Ori
public void start() {
FLog.i(ReactConstants.TAG, "orientation detect enabled.");
mOrientationListener.enable();
- ctx.registerReceiver(mReceiver, new IntentFilter("onConfigurationChanged"));
+ ctx.registerReceiver(mReceiver, new IntentFilter("onConfigurationChanged"), ctx.RECEIVER_NOT_EXPORTED);
}
Or manually add the ctx.RECEIVER_NOT_EXPORTED
to the ctx.registerReceiver
and then patch the lib, it will create same file
@AptypTheKing Thank you π β
. I also found a solution for this from React native release.
facebook/react-native@177d97d
@AptypTheKing Thank you π β . I also found a solution for this from React native release. facebook/react-native@177d97d
It doesn't work for me
@AptypTheKing Thank you π β . I also found a solution for this from React native release. facebook/react-native@177d97d
It doesn't work for me
That exact change won't. It was an example of what to fix in this project. This line needs updating:
https://github.com/react-native-share/react-native-share/blob/main/android/src/main/java/cl/json/social/TargetChosenReceiver.java#L49
This fixes it for me:
--- a/node_modules/react-native-share/android/src/main/java/cl/json/social/TargetChosenReceiver.java
+++ b/node_modules/react-native-share/android/src/main/java/cl/json/social/TargetChosenReceiver.java
@@ -46,7 +46,7 @@ public class TargetChosenReceiver extends BroadcastReceiver {
context.unregisterReceiver(sLastRegisteredReceiver);
}
sLastRegisteredReceiver = new TargetChosenReceiver();
- context.registerReceiver(sLastRegisteredReceiver, new IntentFilter(sTargetChosenReceiveAction));
+ context.registerReceiver(sLastRegisteredReceiver, new IntentFilter(sTargetChosenReceiveAction), Context.RECEIVER_EXPORTED);
}
Intent intent = new Intent(sTargetChosenReceiveAction);
π This issue has been resolved in version 10.0.0 π
The release is available on:
Your semantic-release bot π¦π
I am on react-native-share 10.0.2 with RN 0.73.4, and this issue still exists on android 14 @MateusAndrade
what am I missing?
EDIT: my bad, apparently it may be due to react-native-iap that's also raising the same issue
facing the same issue in my project as well. What exact config need to be done?.
facing the same issue in my project as well. What exact config need to be done?.
There isn't any config needed, just make sure to use their latest version that's compatible with android 14.
On the other hand, like myself make sure it's related to this library and not a different one which might trigger the same issue (and also need to be upgraded)
I had the same issue, with the package react-native-settings in the RNSettingsModule.java file, but fixed with this patch
diff --git a/node_modules/react-native-settings/android/build.gradle b/node_modules/react-native-settings/android/build.gradle
index 6f8e7d0..f85c9dd 100644
--- a/node_modules/react-native-settings/android/build.gradle
+++ b/node_modules/react-native-settings/android/build.gradle
@@ -1,6 +1,7 @@
buildscript {
repositories {
google()
+ jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
diff --git a/node_modules/react-native-settings/android/src/main/java/io/rumors/reactnativesettings/RNSettingsModule.java b/node_modules/react-native-settings/android/src/main/java/io/rumors/reactnativesettings/RNSettingsModule.java
index b0f44c5..84a017c 100644
--- a/node_modules/react-native-settings/android/src/main/java/io/rumors/reactnativesettings/RNSettingsModule.java
+++ b/node_modules/react-native-settings/android/src/main/java/io/rumors/reactnativesettings/RNSettingsModule.java
@@ -1,6 +1,7 @@
package io.rumors.reactnativesettings;
+import android.os.Build;
import android.provider.Settings;
import android.content.Intent;
import android.content.IntentFilter;
@@ -91,7 +92,11 @@ public class RNSettingsModule extends ReactContextBaseJavaModule {
private void registerReceiver(Context reactContext, String filter, BroadcastReceiver receiver) {
IntentFilter intentFilter = new IntentFilter(filter);
- reactContext.registerReceiver(receiver, intentFilter);
+ if (Build.VERSION.SDK_INT >= 34 && reactContext.getApplicationInfo().targetSdkVersion >= 34) {
+ reactContext.registerReceiver(receiver, intentFilter, Context.RECEIVER_EXPORTED);
+ } else {
+ reactContext.registerReceiver(receiver, intentFilter);
+ }
}
private void initReceivers() {
I am on react-native-share 10.0.2 with RN 0.73.4, and this issue still exists on android 14 @MateusAndrade
what am I missing?
EDIT: my bad, apparently it may be due to react-native-iap that's also raising the same issue
same issue i'm facing