Sushant Shivraj
Sushant Shivraj

Reputation: 21

Migrating Api level 33 to 34 react native android app

I am trying to migrate my app from api level 33 to 34, I am using gradle version 8.0.0, and jdk 17 it is returning an error when I am trying to build.

package.json

"dependencies":{
   "@notifee/react-native":"^7.6.1",
   "@react-native-async-storage/async-storage":"^1.17.7",
   "@react-native-community/checkbox":"0.5.12",
   "@react-native-community/netinfo":"^9.3.7",
   "@react-native-firebase/app":"16.2.0",
   "@react-native-firebase/crashlytics":"^17.4.1",
   "@react-native-firebase/messaging":"16.2.0",
   "@react-native-masked-view/masked-view":"^0.2.7",
   "@react-navigation/bottom-tabs":"^6.3.2",
   "@react-navigation/native":"^6.0.11",
   "@react-navigation/stack":"^6.2.2",
   "@reduxjs/toolkit":"^1.8.3",
   "axios":"^1.3.4",
   "i18next":"^21.8.14",
   "lodash":"^4.17.21",
   "moment-timezone":"^0.5.41",
   "paper":"^0.12.17",
   "prop-types":"^15.8.1",
   "react":"18.0.0",
   "react-i18next":"^11.18.3",
   "react-native":"^0.70.1",
   "react-native-autocomplete-dropdown":"^2.1.0",
   "react-native-device-info":"^10.4.0",
   "react-native-document-picker":"^8.1.3",
   "react-native-file-viewer":"^2.1.5",
   "react-native-flash-message":"^0.3.1",
   "react-native-flipper":"^0.156.0",
   "react-native-fs":"^2.20.0",
   "react-native-gesture-handler":"^2.5.0",
   "react-native-paper":"4.12.4",
   "react-native-reanimated":"^2.9.1",
   "react-native-responsive-screen":"^1.4.2",
   "react-native-safe-area-context":"^4.3.1",
   "react-native-screens":"^3.15.0",
   "react-native-spinkit":"^1.5.1",
   "react-native-splash-screen":"^3.3.0",
   "react-native-switch":"^1.5.1",
   "react-native-vector-icons":"^9.2.0",
   "react-redux":"^8.0.2",
   "redux-flipper":"^2.0.2",
   "redux-persist":"^6.0.0"
},

I have tried changing gradle version and targetSdk and compileSdkversion

Upvotes: 2

Views: 1300

Answers (2)

Joseph
Joseph

Reputation: 29

Only change buildToolVersion and targetSdkVersion, it will pass

build.gradle(project level)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 34

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "23.1.7779620"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.4.2")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("com.google.gms:google-services:4.3.8")
    }
}

Upvotes: 0

Urvin Radadiya
Urvin Radadiya

Reputation: 94

I'm using Mac M1 and below solution is works for me...!!!

Step : 1

Update buildToolsVersion to 34.0.0, minSdkVersion to 24, targetSdkVersion to 34 in build.gradle(app module) file.

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 24
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "21.4.7075529"
        androidXCore = "1.6.0"
    }
}

Step : 2

Update react-native-screens plugin to 3.32.0 and other plugin if required.

Step : 3

Update build:gradle to 7.4.2. in build.gradle(app module) file. If possible this is an update from Android Studio.

buildscript {
    ext {
      ...
    }
    repositories {
      ...
    }
    dependencies {
        classpath('com.android.tools.build:gradle:7.4.2')
    }
}

Step : 4

Add this method in MainApplication.java file.

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import org.jetbrains.annotations.Nullable;
...

@SuppressLint({"WrongConstant", "UnspecifiedRegisterReceiverFlag"})
@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);
  }
}

Step : 5

Add below code in build.gradle(project module) file.

dependencies {
  ...
  implementation 'org.jetbrains:annotations:16.0.2'
  ...
  implementation ("androidx.appcompat:appcompat:1.3.1") {
      version {
          strictly '1.3.1'
      }
  }
}

Step : 6

Clean project and then compile project.

cd android; ./gradlew clean; cd .. npx react-native run-android

Upvotes: 2

Related Questions