skip to Main Content

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:

  • React version: 18.2.0
  • React Native version: 0.72.3

Steps I’ve taken so far:

  1. Updated compileSdkVersion and targetSdkVersion to 34 in android/app/build.gradle.
  2. Cleaned the project using ./gradlew clean.
  3. Reinstalled node modules rm -rf node_modules && npm install or yarn install
  4. Rebuilt the project with npx react-native run-android
  5. Started the Metro server manually using 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.

2

Answers


  1. 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'
        // ...
    }
    
    Login or Signup to reply.
  2. I read you need to upgrade react-native to 0.74

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search