将 Api 级别 33 迁移到 34 反应本机 Android 应用程序

问题描述 投票:0回答:1

我正在尝试将我的应用程序从 api 级别

33
迁移到
34
,我正在使用 gradle 版本
8.0.0
,而 jdk
17
在我尝试构建时返回错误。

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"
},

我尝试过更改gradle版本和targetSdk和compileSdkversion

android react-native build.gradle targetsdkversion
1个回答
0
投票

我正在使用 Mac M1,下面的解决方案对我有用......!!!

步骤:1

更新buildToolsVersion到34.0.0,minSdkVersion到24, build.gradle(app module) 文件中的 targetSdkVersion 为 34。

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

步骤:2

更新react-native-screens插件到3.32.0和其他插件如果 必填。

步骤:3

更新 build:gradle 至 7.4.2。在 build.gradle(应用程序模块)文件中。如果 这可能是 Android Studio 的更新。

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

步骤:4

将此方法添加到MainApplication.java文件中。

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);
  }
}

步骤:5

在build.gradle(项目模块)文件中添加以下代码。

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

步骤:6

清理项目然后编译项目。

cd 安卓; ./gradlew 干净; cd .. npx react-native run-android

© www.soinside.com 2019 - 2024. All rights reserved.