rn-fetch-blob icon indicating copy to clipboard operation
rn-fetch-blob copied to clipboard

RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED

Open saikiran02299 opened this issue 11 months ago • 43 comments

Hi ! error One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts

image Screenshot_1

saikiran02299 avatar Mar 20 '24 02:03 saikiran02299

i am also face this error any one solve this ?????

Devangramani48 avatar Mar 21 '24 08:03 Devangramani48

Thi is related to Android SDK 34 where you must explicitly specify export behaviour for broadcasts. It was fixed in RN however this library doesn't seem to be updated.

I've fixed it by updating it manually. You can try using this patch:

diff --git a/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java b/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
index a8abd71..efa1b46 100644
--- a/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
+++ b/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
@@ -196,7 +196,11 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
                 DownloadManager dm = (DownloadManager) appCtx.getSystemService(Context.DOWNLOAD_SERVICE);
                 downloadManagerId = dm.enqueue(req);
                 androidDownloadManagerTaskTable.put(taskId, Long.valueOf(downloadManagerId));
-                appCtx.registerReceiver(this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
+                if (Build.VERSION.SDK_INT >= 34 && appCtx.getApplicationInfo().targetSdkVersion >= 34) {
+                  appCtx.registerReceiver(this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE), Context.RECEIVER_EXPORTED);
+                }else{
+                  appCtx.registerReceiver(this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
+                }
                 return;
             }
 

rada avatar Apr 02 '24 02:04 rada

Thi is related to Android SDK 34 where you must explicitly specify export behaviour for broadcasts. It was fixed in RN however this library doesn't seem to be updated.

I've fixed it by updating it manually. You can try using this patch:

diff --git a/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java b/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
index a8abd71..efa1b46 100644
--- a/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
+++ b/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
@@ -196,7 +196,11 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
                 DownloadManager dm = (DownloadManager) appCtx.getSystemService(Context.DOWNLOAD_SERVICE);
                 downloadManagerId = dm.enqueue(req);
                 androidDownloadManagerTaskTable.put(taskId, Long.valueOf(downloadManagerId));
-                appCtx.registerReceiver(this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
+                if (Build.VERSION.SDK_INT >= 34 && appCtx.getApplicationInfo().targetSdkVersion >= 34) {
+                  appCtx.registerReceiver(this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE), Context.RECEIVER_EXPORTED);
+                }else{
+                  appCtx.registerReceiver(this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
+                }
                 return;
             }
 

Thanks for the answer, that really helped !!

shreykul avatar Apr 02 '24 10:04 shreykul

Thanks for the answer, that helped me as well!!

ajaybor0 avatar Apr 22 '24 06:04 ajaybor0

Yeah, it helps but now after downloading the file, my app crash

domabyte avatar Apr 22 '24 16:04 domabyte

it's working fine for me.

ajaybor0 avatar Apr 23 '24 04:04 ajaybor0

Same, the file gets downloaded but right after that the app crashes with the same error One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts

Subramanyarao11 avatar May 11 '24 11:05 Subramanyarao11

Yeah, it helps but now after downloading the file, my app crash

Did you find any solution?

Subramanyarao11 avatar May 11 '24 11:05 Subramanyarao11

Due to lack of information and for quick need, i ditch using rn-fetch-blob and start using react-native-fs, and it's working perfectly

domabyte avatar May 11 '24 13:05 domabyte

I updated to 0.74.2 - now there is no red screen but the app is like close

befaster avatar Jun 07 '24 10:06 befaster

I have changed the tagetSDKVersion = 33 and it works for me

miradario avatar Jun 10 '24 18:06 miradario

@miradario thanks. I just seems finally was able to fix it. The advice maybe which can help. I chanage packages which was hardcode vesion. I mean for example "abc-package": "x.x.x" to"abc-package": "^x.x.x". Not sure it can help but maybe you can find this way the problem library.

befaster avatar Jun 10 '24 19:06 befaster

I have changed the tagetSDKVersion = 33 and it works for me

Yes, there's a lot of breakage in targetSDKVersion 34, it's good if we just rely on 33

domabyte avatar Jun 11 '24 13:06 domabyte

From August 31 it is mandatory to update to latest version API level 34. This issue needs to fixed immediately :(

Warning from google: From Aug 31, 2024, if your target API level is not within 1 year of the latest Android release, you won't be able to update your app.

dooamindshine avatar Jul 12 '24 14:07 dooamindshine

We're still trying to figure out how to resolve the below issue, I've tried all the suggestions but still getting the below Error:

2024-07-14 16:20:12.226 3081-5023/E/unknown:ReactNative: Exception in native call 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 at android.os.Parcel.createExceptionOrNull(Parcel.java:3057) at android.os.Parcel.createException(Parcel.java:3041) at android.os.Parcel.readException(Parcel.java:3024) at android.os.Parcel.readException(Parcel.java:2966) at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:6205) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1863) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1803) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1791) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:766) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:766) at io.expo.appearance.RNCAppearanceModule.onHostResume(RNCAppearanceModule.java:125) at com.facebook.react.bridge.ReactContext.onHostResume(ReactContext.java:240) at com.facebook.react.ReactInstanceManager.moveToResumedLifecycleState(ReactInstanceManager.java:719) at com.facebook.react.ReactInstanceManager.moveReactContextToCurrentLifecycleState(ReactInstanceManager.java:754) at com.facebook.react.ReactInstanceManager.setupReactContext(ReactInstanceManager.java:1086) at com.facebook.react.ReactInstanceManager.access$1500(ReactInstanceManager.java:131) at com.facebook.react.ReactInstanceManager$5$2.run(ReactInstanceManager.java:1044) at android.os.Handler.handleCallback(Handler.java:958) at android.os.Handler.dispatchMessage(Handler.java:99) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27) at android.os.Looper.loopOnce(Looper.java:222) at android.os.Looper.loop(Looper.java:314) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226) at java.lang.Thread.run(Thread.java:1012) Caused by: android.os.RemoteException: Remote stack trace: at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:14690) at android.app.IActivityManager$Stub.onTransact$registerReceiverWithFeature$(IActivityManager.java:12225) at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:3194) at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2887) at android.os.Binder.execTransactInternal(Binder.java:1346)

Can someone advise here as by Aug 31 we must add our apps with SDK 34.

I've already tried the below with no success:

in the MainActivity.java

`@Override public Intent registerReceiver(@Nullable BroadcastReceiver receiver, IntentFilter filter) {

if (Build.VERSION.SDK_INT >= 34 && getApplicationInfo().targetSdkVersion >= 34) {
  return super.registerReceiver(receiver, filter, RECEIVER_EXPORTED);
} else {
  return super.registerReceiver(receiver, filter);
}

}`

Also tried to add the code into: /node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java

private void compatRegisterReceiver( Context context, BroadcastReceiver receiver, IntentFilter filter, boolean exported) { if (Build.VERSION.SDK_INT >= 34 && context.getApplicationInfo().targetSdkVersion >= 34) { context.registerReceiver( receiver, filter, exported ? Context.RECEIVER_EXPORTED : Context.RECEIVER_NOT_EXPORTED); } else { context.registerReceiver(receiver, filter); } }

And change the below call: mApplicationContext.registerReceiver(mReloadAppBroadcastReceiver, filter);

to: compatRegisterReceiver(mApplicationContext, mReloadAppBroadcastReceiver, filter, true);

Also not works,

Added the Implementations into the dependencies of build.gradle also not helped. implementation 'org.jetbrains:annotations:16.0.2' implementation 'com.google.android.play:app-update:2.1.0'

The only thing succeeded is the failure of "classes2.dex' is not allowed."

Which fixed in the MainActivity after super.onCreate(); by calling the below line getCodeCacheDir().setReadOnly();

Can someone advise here with more ideas?

I'm still using "react-native": "0.64.3" and not sure I can do such movement now to new version.

rabiaah avatar Jul 14 '24 13:07 rabiaah

I think I've figure out the issue, Let me explain,

In general the first part of the Exception is a Generic error and refers to the ReactNative module which contains the below call:

activity.registerReceiver

The best way to fix the issue, first search in your Exception which module is failing into, for example, in each Exception you will find "registerReceiver" and right after will be "onHostResume".

In my exception it was referring to the below line io.expo.appearance.RNCAppearanceModule.onHostResume(RNCAppearanceModule.java:125) at

So I've accessed "RNCAppearanceModule.java" file and somehow I saw that it contains old version of the register call as this module not updated frequently.

Existing line: activity.registerReceiver(mBroadcastReceiver, new IntentFilter("onConfigurationChanged"));

I've added change it with the below line (Added the 3rd parameter which is needed): activity.registerReceiver(mBroadcastReceiver, new IntentFilter("onConfigurationChanged"), Context.RECEIVER_EXPORTED);

Make sure "Context" is imported.

Still you must get the below steps done to fix the issue:

  1. build.gradle

    targetSdkVersion = 34

  2. MainApplication.java

    Import the below libs

import android.content.BroadcastReceiver; import android.content.Intent; import android.content.IntentFilter; import android.os.Build; import org.jetbrains.annotations.Nullable;

  1. Add override function

Override public Intent registerReceiver(Nullable 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);
}

}

Please add @ before Override and Nullable.

  1. In the build.grade, Add the below implementation in the dependencies implementation 'org.jetbrains:annotations:16.0.2'

Please try and update if it'e working for you.

Thanks All, My issue resolved finally!

rabiaah avatar Jul 14 '24 18:07 rabiaah

I think I've figure out the issue, Let me explain,

In general the first part of the Exception is a Generic error and refers to the ReactNative module which contains the below call:

activity.registerReceiver

The best way to fix the issue, first search in your Exception which module is failing into, for example, in each Exception you will find "registerReceiver" and right after will be "onHostResume".

In my exception it was referring to the below line io.expo.appearance.RNCAppearanceModule.onHostResume(RNCAppearanceModule.java:125) at

So I go to "RNCAppearanceModule.java" file and somehow I saw that it contains old version of the register call as this module not updated frequently.

Existing line: activity.registerReceiver(mBroadcastReceiver, new IntentFilter("onConfigurationChanged"));

I've added change it with the below line (Added the 3rd parameter which is needed): activity.registerReceiver(mBroadcastReceiver, new IntentFilter("onConfigurationChanged"), Context.RECEIVER_EXPORTED);

Additionally to that fix you still need to make the below changes:

  1. build.gradle

    targetSdkVersion = 34

  2. MainApplication.java

    Import the below libs

import android.content.BroadcastReceiver; import android.content.Intent; import android.content.IntentFilter; import android.os.Build; import org.jetbrains.annotations.Nullable;

  1. Add override function

Override public Intent registerReceiver(Nullable 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);
}

}

Please add @ before Override and Nullable.

  1. In the build.grade, Add the below implementation in the dependencies implementation 'org.jetbrains:annotations:16.0.2'

Please try and update if it'e working for you.

Thanks All, My issue resolved finally!

It didn't helped in my case

DigenPrimeApps avatar Jul 18 '24 11:07 DigenPrimeApps

Please share the exception to try understand what you're facing

rabiaah avatar Jul 18 '24 11:07 rabiaah

Please share the exception to try understand what you're facing

yeah It is solved, in my case, I have to change this line in react-native-orientation package old line activity.registerReceiver(receiver, new IntentFilter("onConfigurationChanged"));

to new line activity.registerReceiver(receiver, new IntentFilter("onConfigurationChanged"),Context.RECEIVER_NOT_EXPORTED);

now it is resolved for me

DigenPrimeApps avatar Jul 18 '24 12:07 DigenPrimeApps

@rabiaah For me its working too. I just had to add import android.content.Context; :)

We might need to wait for the libraries to update their calls to be fully compatible with the new API level requirements

joerndyherrn avatar Jul 19 '24 09:07 joerndyherrn

I don't use this library but still get the same error.

You can try using this patch:

{ "name": "calwaste", "version": "11.0.0", "private": true, "scripts": { "android": "react-native run-android", "start": "react-native start", "test": "jest", "lint": "eslint .js **/.js", "ios": "react-native run-ios --simulator='iPhone 8'", "reinstall:all": "rm -rf node_modules && rm -rf ./iosM/Pods && yarn install && cd ios && pod deintegrate && pod cache clean --all && pod install" }, "dependencies": { "@bugsnag/plugin-react-navigation": "^7.5.0", "@bugsnag/react-native": "^7.5.2", "@hookform/resolvers": "^1.2.0", "@invertase/react-native-apple-authentication": "^2.1.0", "@notifee/react-native": "^7.0.1", "@react-native-community/async-storage": "^1.6.1", "@react-native-community/cli-platform-android": "^11.3.1", "@react-native-community/datetimepicker": "^3.5.2", "@react-native-firebase/app": "^17.5.0", "@react-native-firebase/crashlytics": "^17.5.0", "@react-native-firebase/installations": "^17.5.0", "@react-native-firebase/messaging": "^17.5.0", "@react-native-google-signin/google-signin": "^8.2.1", "@react-native-picker/picker": "^2.4.10", "@react-navigation/bottom-tabs": "^5.11.7", "@react-navigation/native": "^6.0.13", "@react-navigation/stack": "^6.3.4", "axios": "^0.21.3", "buffer": "^5.5.0", "fastestsmallesttextencoderdecoder": "^1.0.22", "i18n-js": "^3.8.0", "joi": "^17.3.0", "moment": "^2.24.0", "pod-install": "^0.1.38", "query-string": "^6.9.0", "ramda": "^0.27.2", "react": "17.0.2", "react-content-loader": "^5.0.4", "react-hook-form": "^6.8.2", "react-native": "0.68.1", "react-native-actions-sheet": "^0.5.4", "react-native-calendars": "^1.1269.0", "react-native-communications": "^2.2.1", "react-native-default-preference": "^1.4.3", "react-native-device-info": "^10.3.0", "react-native-fast-image": "^8.6.1", "react-native-flash-message": "^0.1.23", "react-native-flipper": "^0.127.0", "react-native-form-validator": "^0.3.5", "react-native-geolocation-service": "^5.3.1", "react-native-gesture-handler": "^1.8.0", "react-native-image-picker": "^5.3.1", "react-native-image-slider-box": "^2.0.7", "react-native-iphone-x-helper": "^1.3.1", "react-native-keyboard-aware-scroll-view": "^0.8.0", "react-native-modal": "^11.5.6", "react-native-modal-datetime-picker": "^11.0.0", "react-native-orientation": "^3.1.3", "react-native-permissions": "^3.8.0", "react-native-picker-select": "^8.0.4", "react-native-progress": "^5.0.0", "react-native-rate": "^1.2.12", "react-native-render-html": "^5.1.0", "react-native-responsive-screen": "^1.2.2", "react-native-restart": "^0.0.24", "react-native-safe-area-context": "^3.1.8", "react-native-screens": "^2.11.0", "react-native-share": "^3.0.0", "react-native-size-matters": "^0.1.6", "react-native-smooth-pincode-input": "^1.0.9", "react-native-splash-screen": "^3.2.0", "react-native-svg": "^12.1.0", "react-native-swipe-gestures": "^1.0.5", "react-native-swiper": "^1.6.0", "react-native-swiper-flatlist": "^3.2.3", "react-native-uuid": "^1.4.9", "react-native-webview": "^11.23.1", "react-redux": "^5.1.1", "reactotron-redux": "^3.1.3", "redux": "^4.0.4", "redux-logger": "^3.0.6", "redux-persist": "^5.10.0", "redux-thunk": "^2.3.0", "seamless-immutable": "^7.1.4", "url-parse": "^1.4.7", "use-debounce": "^3.4.2" }, "devDependencies": { "@babel/core": "^7.12.9", "@babel/runtime": "^7.12.5", "@react-native-community/eslint-config": "^2.0.0", "babel-jest": "^26.6.3", "eslint": "^7.15.0", "eslint-config-airbnb": "^17.1.1", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.14.3", "eslint-plugin-react-hooks": "^1.6.1", "eslint-plugin-react-native": "^3.8.1", "jest": "^26.6.3", "jetifier": "^1.6.6", "metro": "^0.64.0", "metro-config": "^0.64.0", "metro-react-native-babel-preset": "^0.66.2", "react-test-renderer": "^17.0.2", "reactotron-react-native": "^5.0.0", "reactotron-redux": "^3.1.1" }, "jest": { "preset": "react-native" } }

alieliacik avatar Jul 23 '24 22:07 alieliacik

Please share the exception to try understand what you're facing

yeah It is solved, in my case, I have to change this line in react-native-orientation package old line activity.registerReceiver(receiver, new IntentFilter("onConfigurationChanged"));

to new line activity.registerReceiver(receiver, new IntentFilter("onConfigurationChanged"),Context.RECEIVER_NOT_EXPORTED);

now it is resolved for me

Thanks body. I have been looking for a solution since last week.

alieliacik avatar Jul 23 '24 22:07 alieliacik

i am still facing same issue in React Native application development , Please help me to resolve this issue! photo_2024-07-07_16-39-31

gourav3309 avatar Jul 25 '24 12:07 gourav3309

i am still facing same issue in React Native application development , Please help me to resolve this issue!

photo_2024-07-07_16-39-31

Can you share the full Exception?

rabiaah avatar Jul 25 '24 13:07 rabiaah

It's related only for Android devices with SDK34, why you're sharing the full React code?

rabiaah avatar Jul 25 '24 17:07 rabiaah

Please share the solution to this issue. I am sharing my code because I have implemented every method I could think of to resolve it.

gourav3309 avatar Jul 25 '24 17:07 gourav3309

Solution already shared, if you can share the full exception then only we might help as it's not related to react code.

rabiaah avatar Jul 25 '24 17:07 rabiaah

please pin the solution , Expectation is i just want to download the pdf in device , whenever i click on download button , my pdf file downloads but my app crash ,

gourav3309 avatar Jul 25 '24 17:07 gourav3309

Please share the exception what is not clear dear?

Anyway, I have updated before the below solution, please review the posts here.

https://github.com/joltup/rn-fetch-blob/issues/866#issuecomment-2227436658

rabiaah avatar Jul 25 '24 17:07 rabiaah

I think this repository is no longer maintained by the maintainer. I'll share how to modify the code automatically. After creating a scripts folder, create update_rnfetchblobreq.js and enter the code below.

const fs = require("fs");
const path = require("path");

const filePath = path.join(
  "node_modules",
  "rn-fetch-blob",
  "android",
  "src",
  "main",
  "java",
  "com",
  "RNFetchBlob",
  "RNFetchBlobReq.java",
);

fs.readFile(filePath, "utf8", (err, data) => {
  if (err) {
    console.error("File read error:", err);
    return;
  }

  const pattern = /appCtx\.registerReceiver\(this, new IntentFilter\(DownloadManager\.ACTION_DOWNLOAD_COMPLETE\)\);/;
  const replacement = `if (Build.VERSION.SDK_INT >= 34 && appCtx.getApplicationInfo().targetSdkVersion >= 34) {.
                  appCtx.registerReceiver(this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE), Context.RECEIVER_EXPORTED);
                } else {
                  appCtx.registerReceiver(this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
                }`;

  const updatedContent = data.replace(pattern, replacement);

  fs.writeFile(filePath, updatedContent, "utf8", (err) => {
    if (err) {
      console.error("File write error:", err);
    } else {
      console.log("File was successfully updated");
    }
  });
});

Then, inside your package.json file script, add the following code

"postinstall": "node scripts/update_rnfetchblobreq.js",

Once this is done, the code will be automatically modified after npm i.

ChanghyeonYoon avatar Jul 26 '24 02:07 ChanghyeonYoon