首页 > 解决方案 > React Expo 更改目标 Android API

问题描述

最近我们使用 react expo 构建 Android 应用程序并使用以下命令expo build:android -t apk或 Android App Bundle构建签名 APKexpo build:android -t app-bundle

在我们构建签名 APK 后,我们尝试上传到 Playstore,但出现了一些错误,要求我们将目标 API 从 26 升级到 28。在 SO 上探索和阅读了几个 QA,其中许多是针对 React Native 的。我们如何将我们的 APK 发布到 Play 商店?

这里是app.json

{
  "expo": {
    "name": "***",
    "slug": "***",
    "privacy": "public",
    "sdkVersion": "32.0.0",
    "platforms": [
      "ios",
      "android"
    ],
    "version": "1.2.3",
    "orientation": "portrait",
    "icon": "./assets/logo.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "enabled": true,
      "checkAutomatically": "ON_LOAD",
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true
    },
    "android": {
      "package": "com.qreatiq.foodmart",
      "permissions": [
        "CAMERA"
      ],
      "googleServicesFile": "./google-services.json",
    },
  }
}

我们已尝试检查文档here,并且有 compileSDKVersion 或相关的属性,如本机应用程序。

在本机应用程序中,我们可以轻松配置如下

compileSdkVersion 27
buildToolsVersion "27.0.3"
minSdkVersion 16
targetSdkVersion 27

如何在 React Expo 上做到这一点?

developer.android.com阅读后更新 1

当您上传 APK 时,它需要满足 Google Play 的目标 API 级别要求。从 2019 年 8 月 1 日开始,Google Play 要求新应用至少面向 Android 9.0(API 级别 28),并且应用更新从 2​​019 年 11 月 1 日起面向 Android 9.0。在这些日期之前,新应用和应用更新必须至少面向 Android 8.0(API 级别 26)。

对那些事情还是没有任何想法。

标签: androidreact-nativeexpo

解决方案


按着这些次序:

  1. 关闭您的 Expo CLI 服务器
  2. app.json,更改sdkVersion"34.0.0"

  3. package.json中,更改这些依赖项:

    • react-native"https://github.com/expo/react-native/archive/sdk-34.0.0.tar.gz"
    • expo"^34.0.3"
    • react"16.8.3"——(这个确切的版本)
    • react-navigation"^3.11.1"
    • jest-expo"^34.0.0"(如果你使用它)
    • sentry-expo"~1.13.0"(如果你使用它)
  4. 如果你使用react-navigation你也应该运行expo install react-native-gesture-handler react-native-reanimated

  5. 删除项目node_modules目录并npm install再次运行或使用yarn

  6. expo start -c

在这些步骤之后,它应该可以工作。

来源:https ://blog.expo.io/expo-sdk-34-is-now-available-4f7825239319


推荐阅读