I recently updated my React Native project's compileSdkVersion from 33 to 34 to comply with Google's new policy. After making this change, I am unable to connect to the Metro server. Here are the details of my android/app/build.gradle configuration:
ext {
buildToolsVersion = "33.0.0"
minSdkVersion = 28
compileSdkVersion = 34
targetSdkVersion = 34
ndkVersion = "25.0.8775105"
}
android {
compileSdkVersion = 34
defaultConfig {
minSdkVersion = 28
targetSdkVersion = 34
}
}
My project setup includes:
Steps I've taken so far:
rm -rf node_modules && npm install or yarn install
npx react-native run-android
npx react-native start
Despite these steps, the Metro server fails to connect when running the app. I have also verified that all my dependencies are up to date.First update the android/build.gradle
compileSdkVersion = 34
targetSdkVersion = 34
if your code work file then ok In my case my app crash after these changes so I reslved app crash my changes these
MainApplication.java
// Add imports
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import org.jetbrains.annotations.Nullable;
// ...
// Put this above "public void onCreate()":
@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);
}
}
// ....
app/build.gradle
dependencies {
// ...
implementation 'org.jetbrains:annotations:16.0.2'
// ...
}