I'm upgrading my targetSdkVersion to 34
buildscript {
ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 26
compileSdkVersion = 33
targetSdkVersion = 34
supportLibVersion = 34
}
and I've run into this error when running the react-native app.
I've seen a lot of solutions online that suggest adding
context.registerReceiver(broadcastReceiver, intentFilter, RECEIVER_EXPORTED);
But they don't mention where it needs to be added. I've only worked on the react-native side so it would help if I had more details about the Android specific updates.
I added the following to MainApplication.java
file.
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.Context;
import android.content.IntentFilter;
import android.os.Build;
import org.jetbrains.annotations.Nullable;
and before public void onCreate()
in the same file,
@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);
}
}
In android/build.gradle
under dependencies
classpath("com.android.tools.build:gradle:7.3.1")
In android/gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
I also kept getting the error
couldn't find DSO to load: libhermes.so
For which I had to upgrade react-native-reanimated
to 3.5.4.
I also upgraded my react-native-screens
to 3.22.0
.
My other main library versions
"react-native": "0.71.4",
"react": "18.2.0",
"@react-navigation/native": "^6.1.6",
"@react-navigation/stack": "^6.3.16",
This fixed things for me