React Native App Crashes — On upgrading to targetSdkVersion 34(Android 14)
Upon launching the application, I encountered an issue where the app crashes immediately on launch when I set my targetSdkVersion to 34 (for Android 14).
Error :
- Caused by: 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.
- Caused by: java.lang.RuntimeException: Requested enabled DevSupportManager, but BridgeDevSupportManager class was not found or could not be created.
In my opinion, react-native-orientation and rn-fetch-blob are some of the packages that cause this issue.
follow the below steps to resolve the issue
in your MainApplication.java
import android.content.Context; // make sure you are not importing multiple times
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import org.jetbrains.annotations.Nullable;
@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);
}
}
and Ensure that you insert this(@Override…) code before the onCreate() method.
insert this line inside android/app/build.gradle
dependencies.
implementation 'org.jetbrains:annotations:16.0.2'
re-run the project.
For some people, this works.
For others, if the issue persists after implementing the above steps, check if you are using react-native-orientation.
If yes, follow the steps below.
diff --git a/node_modules/react-native-orientation/android/build.gradle b/node_modules/react-native-orientation/android/build.gradle
index e09fb27..aaf30a6 100644
--- a/node_modules/react-native-orientation/android/build.gradle
+++ b/node_modules/react-native-orientation/android/build.gradle
@@ -1,20 +1,20 @@
apply plugin: 'com.android.library'
android {
- compileSdkVersion 23
- buildToolsVersion "23.0.1"
+ compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : 23
+ buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : "23.0.1"
defaultConfig {
- minSdkVersion 16
- targetSdkVersion 22
+ minSdkVersion rootProject.hasProperty('minSdkVersion') ? rootProject.minSdkVersion : 16
+ targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : 22
versionCode 1
versionName "1.0"
- ndk {
- abiFilters "armeabi-v7a", "x86"
- }
+ // ndk {
+ // abiFilters "armeabi-v7a", "x86"
+ // }
}
}
dependencies {
- compile "com.facebook.react:react-native:+"
+ implementation "com.facebook.react:react-native:+"
}
diff --git a/node_modules/react-native-orientation/android/src/main/java/com/github/yamill/orientation/OrientationModule.java b/node_modules/react-native-orientation/android/src/main/java/com/github/yamill/orientation/OrientationModule.java
index 85331ae..3df9a1f 100644
--- a/node_modules/react-native-orientation/android/src/main/java/com/github/yamill/orientation/OrientationModule.java
+++ b/node_modules/react-native-orientation/android/src/main/java/com/github/yamill/orientation/OrientationModule.java
@@ -150,7 +150,7 @@ public class OrientationModule extends ReactContextBaseJavaModule implements Lif
FLog.e(ReactConstants.TAG, "no activity to register receiver");
return;
}
- activity.registerReceiver(receiver, new IntentFilter("onConfigurationChanged"));
+ activity.registerReceiver(receiver, new IntentFilter("onConfigurationChanged"), Context.RECEIVER_NOT_EXPORTED);
}
@Override
public void onHostPause() {
refrenece from https://github.com/yamill/react-native-orientation/issues/429
i hope this helps.
If it works fine give a clap 👏