React Native - 上传到 Google Play 出错:您的应用当前针对 API 级别 30,必须至少针对 API 级别 31。

10

我在将我的应用上传到 Google 时遇到了以下错误:

Your app currently targets API level 30 and must target at least API level 31 to ensure it is built on the latest APIs optimized for security and performance. Change your app's target API level to at least 31.

这是我的 android/build.gradle 文件:

buildscript {
    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        ndkVersion = "21.4.7075529"
    }
    ...
}

如何将应用程序目标API升级到31级?

4个回答

5

我最近在Google控制台上看到了这个警告。

为了解决它,我只需将android/app/build.gradle文件中的targetSdkVersion从30更新到31,即可得到以下代码(我还必须确保compileSdkVersion设置为31):

android {
    compileSdkVersion 31 // You can use 
    //...

    defaultConfig {
        targetSdkVersion 31
        // ... 
    }

我需要修改位于android/app文件中的buildscript,具体操作如下:

buildscript {
    ext {
        buildToolsVersion = '30.0.2'
        minSdkVersion = 21
        compileSdkVersion = 31 // You can use ``rootProject.ext.compileSdkVersion`` instead
        targetSdkVersion = // You can use ``rootProject.ext.targetSdkVersion`` instead
        ndkVersion = '21.4.7075529'
        playServicesVersion = '17.0.0' // or find latest version
        androidMapsUtilsVersion = '2.3.0'
    }
    // ...
}

2
  <activity
    android:name=".MainActivity"
    android:exported="true" ... >

在AndroidManifest.xml文件中添加android:exported="true"或android:exported="false"。

buildscript {
    ext {
        buildToolsVersion = "31.0.0"
        minSdkVersion = 21
        compileSdkVersion = 31
        targetSdkVersion = 31
        ndkVersion = "20.1.5948944"
    }
    ...
}

在 android/gradle/build.gradle 中将 compileSdkVersion = 31 和 compileSdkVersion = 31 更改为 [REACT NATIVE APPS]


1
我在将我的应用程序部署到Play Store时也遇到了相同的错误。
所以只需在Your_project/android/build.gradle中将targetSdkVersion = 30更新为targetSdkVersion = 31。
targetSdkVersion = 31

然后运行

cd android

./gradlew clean

1
buildscript {
    ext {
        buildToolsVersion = "31.0.0"
        minSdkVersion = 21
        compileSdkVersion = 31
        targetSdkVersion = 31
        ndkVersion = "20.1.5948944"
    }
    ...
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接