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

RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED #866

Open
saikiran02299 opened this issue Mar 20, 2024 · 47 comments
Open

RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED #866

saikiran02299 opened this issue Mar 20, 2024 · 47 comments

Comments

@saikiran02299
Copy link

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

@Devangramani48
Copy link

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

@rada
Copy link

rada commented Apr 2, 2024

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;
             }
 

@shreykul
Copy link

shreykul commented Apr 2, 2024

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 !!

@ajaybor0
Copy link

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

@domabyte
Copy link

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

@ajaybor0
Copy link

it's working fine for me.

@Subramanyarao11
Copy link

Subramanyarao11 commented May 11, 2024

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
Copy link

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

Did you find any solution?

@domabyte
Copy link

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

@befaster
Copy link

befaster commented Jun 7, 2024

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

@miradario
Copy link

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

@befaster
Copy link

@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.

@domabyte
Copy link

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

@dooamindshine
Copy link

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.

@rabiaah
Copy link

rabiaah commented Jul 14, 2024

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
Copy link

rabiaah commented Jul 14, 2024

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!

@DigenPrimeApps
Copy link

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

@rabiaah
Copy link

rabiaah commented Jul 18, 2024

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

@DigenPrimeApps
Copy link

DigenPrimeApps commented Jul 18, 2024

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

@joerndyherrn
Copy link

@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

@alieliacik
Copy link

alieliacik commented Jul 23, 2024

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
Copy link

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.

@gourav3309
Copy link

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

@rabiaah
Copy link

rabiaah commented Jul 25, 2024

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
Copy link

rabiaah commented Jul 25, 2024

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

@gourav3309
Copy link

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.

@rabiaah
Copy link

rabiaah commented Jul 25, 2024

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

@gourav3309
Copy link

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 ,

@rabiaah
Copy link

rabiaah commented Jul 25, 2024

Please share the exception what is not clear dear?

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

#866 (comment)

@ChanghyeonYoon
Copy link

ChanghyeonYoon commented Jul 26, 2024

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.

@see2ever
Copy link

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.

you could just use "patch-package"

@GeeGYMR
Copy link

GeeGYMR commented Jul 27, 2024

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!

where do i make these changes?, what file?

@Siddhantshelake
Copy link

Detailed explanation and potential issue fixes are added and discussed in this Medium article:
https://medium.com/@siddhantshelake/fixing-broadcastreceiver-crashes-and-metro-server-issues-in-android-14-3b7d05939a43

@gourav3309
Copy link

Thankyou @rabiaah , My issue is resolved

@DanielWoldehana
Copy link

@rabiaah Could you help me, I am receiving the same error as gourav3309 was.

Here is the full Exception:

Exception in native call java.lang.SecurityException: com.myProject.myProject: 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:5684) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755) at com.tintef.HeadphoneDetection.RNHeadphoneDetectionModule.maybeRegisterReceiver(RNHeadphoneDetectionModule.java:72) at com.tintef.HeadphoneDetection.RNHeadphoneDetectionModule.onHostResume(RNHeadphoneDetectionModule.java:151) at com.facebook.react.bridge.ReactContext$1.run(ReactContext.java:267) 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:205) at android.os.Looper.loop(Looper.java:294) at android.app.ActivityThread.main(ActivityThread.java:8177) 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:971) Caused by: android.os.RemoteException: Remote stack trace: at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:13927) at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2570) at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2720) at android.os.Binder.execTransactInternal(Binder.java:1339) at android.os.Binder.execTransact(Binder.java:1275)

@rabiaah
Copy link

rabiaah commented Aug 6, 2024

onHostResume(RNHeadphoneDetectionModule.java:151)

Go to RNHeadphoneDetectionModule.java line 151.

Search for activity.registerReceiver

You need to add as 3rd parameter.

Context.RECEIVER_EXPORTED

Try and update.

@DanielWoldehana
Copy link

DanielWoldehana commented Aug 6, 2024

@rabiaah

onHostResume(RNHeadphoneDetectionModule.java:151)

Go to RNHeadphoneDetectionModule.java line 151.

Search for activity.registerReceiver

You need to add as 3rd parameter.

Context.RECEIVER_EXPORTED

Try and update.

There were no results for the search activity.registerReceiver
line 151 has:
@Override public void onHostResume() { maybeRegisterReceiver(); }

and according to the warnings I am receiving the problem is in RNHeadphoneDetectionModule.java in this function private void maybeRegisterReceiver() it shows a warning at this line:

reactContext.registerReceiver(receiver, new IntentFilter(BluetoothAdapter.EXTRA_STATE));

Warning is: receiver is missing RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED flag for unprotected broadcasts registered for android.bluetooth.adapter.extra.STATE

So I added it like so:

reactContext.registerReceiver(receiver, new IntentFilter(BluetoothAdapter.EXTRA_STATE), Context.RECEIVER_EXPORTED);

but then go this error:
Call requires API level 26 (current min is 16): android.content.ContextWrapper#registerReceiver

@rabiaah
Copy link

rabiaah commented Aug 6, 2024

That's fine, it's the same just add the context to the call

Like:

reactContext.registerReceiver(receiver, new IntentFilter(BluetoothAdapter.EXTRA_STATE), Context.RECEIVER_EXPORTED);

You may need to import Context if not imported already or use any available context inside the class.

@DanielWoldehana
Copy link

@rabiaah I updated my previous comment with some new findings before you replied could you look at it again, thank you! comment

@rabiaah
Copy link

rabiaah commented Aug 6, 2024

Please review my steps shared in the accepted comment, you need to update your gradle.

@johhansantana
Copy link

I was able to debug this same error in my case with adb logcat and look the receiver errors to come up and noticed this orientation library coming up after the receiver errors:

08-20 13:14:12.474 28373 28373 E unknown:ReactNative: 	at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1853)
08-20 13:14:12.474 28373 28373 E unknown:ReactNative: 	at android.app.ContextImpl.registerReceiver(ContextImpl.java:1793)
08-20 13:14:12.474 28373 28373 E unknown:ReactNative: 	at android.app.ContextImpl.registerReceiver(ContextImpl.java:1781)
08-20 13:14:12.474 28373 28373 E unknown:ReactNative: 	at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:757)
08-20 13:14:12.474 28373 28373 E unknown:ReactNative: 	at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:757)
08-20 13:14:12.474 28373 28373 E unknown:ReactNative: 	at org.wonday.orientation.OrientationModule.onHostResume(OrientationModule.java:348)

Went to check for updates on this library called react-native-orientation-locker I was using and they indeed had an update to fix the issue.

This is the file they updated just in case it helps someone:
wonday/react-native-orientation-locker@e0fe656

@ricpham
Copy link

ricpham commented Sep 12, 2024

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 you, I've add your code into this lib,

every body can using my lib already fixed:

https://www.npmjs.com/package/rn-fetch-blob-repair?activeTab=readme

@ceberm
Copy link

ceberm commented Sep 19, 2024

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 you, I've add your code into this lib,

every body can using my lib already fixed:

https://www.npmjs.com/package/rn-fetch-blob-repair?activeTab=readme

In order for me to work I had to put this code on MainActivity and on MainApplication, My RN version is really old (0.63.2) still I was able to compile the app for Api 34,
Thanks for this!

@YuriLima23
Copy link

YuriLima23 commented Oct 3, 2024

@gourav3309
Copy link

gourav3309 commented Oct 3, 2024 via email

@fleita9
Copy link

fleita9 commented Oct 4, 2024

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 you, I've add your code into this lib,
every body can using my lib already fixed:
https://www.npmjs.com/package/rn-fetch-blob-repair?activeTab=readme

In order for me to work I had to put this code on MainActivity and on MainApplication, My RN version is really old (0.63.2) still I was able to compile the app for Api 34, Thanks for this!

hi, how did you put this code in MainActivity?

@Ghazali32
Copy link

I tried nearly everything, but ultimately, I had to remove the react-native-orientation library from my project, and now it’s working fine.

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

No branches or pull requests