首页指南参考教程

运行时版本

了解如何设置应用的运行时版本。


每个更新都针对一个兼容的运行时。每次你为应用构建二进制文件时,它都包含构建时存在的原生代码,并且仅包含该代码,并且构建的这种独特组合和配置是由运行时版本表示的。

¥Every update targets one compatible runtime. Each time you build a binary for your app it includes the native code present at the time of the build and only that code, and this unique combination and configuration of the build is what is represented by the runtime version.

默认情况下,运行时版本由 Expo SDK 版本确定,但如果你在每个 SDK 版本中构建多次,则这将无法充分描述应用的不同运行时版本。在这种情况下,你需要指定 runtimeVersion 以确保你的更新仅传递到兼容的版本。每当你更新项目的原生模块并更改 JS 原生接口时,都应该更新此 runtimeVersion

¥By default, the runtime version is determined by the Expo SDK version, but this will not adequately describe the different runtime versions of your app if you build more than once per SDK release. In this case, you will need to specify a runtimeVersion to ensure your updates are delivered only to compatible builds. This runtimeVersion should be updated whenever you update your project's native modules and change the JS–native interface.

运行时版本字符串必须符合 这种格式

¥The runtime version string must conform to this format.

设置更新的运行时版本

¥Setting the runtime version for an update

使用 app.json 中设置的运行时版本发布的更新将传递到运行相同运行时版本的构建,并且仅传递到这些构建。

¥Updates published with the runtime version set in app.json will be delivered to builds running the same runtime version, and only to those builds.

app.json
{
  "expo": {
    "runtimeVersion": "1.0.0"
  }
}

设置构建的运行时版本

¥Setting the runtime version for a build

托管工作流的配置

¥Configuration for the managed workflow

如果你使用的是 管理工作流程,则 runtimeVersion 在 app.json 中指定:

¥If you are using the managed workflow, runtimeVersion is specified in app.json:

app.json
{
  "expo": {
    "runtimeVersion": "1.0.0"
  }
}

裸工作流程的配置

¥Configuration for the bare workflow

如果你使用的是 裸工作流程,请在 iOS 上的 Android Expo.plist 上的 AndroidManifest.xml 中设置运行时版本。

¥If you are using the bare workflow, set the runtime version in AndroidManifest.xml on Android Expo.plist on iOS.

对于 iOS 版本,请使用键 EXUpdatesRuntimeVersion 将条目添加到 Expo.plist。该值是表示运行时版本的字符串。

¥For an iOS build, add an entry to the Expo.plist with the key EXUpdatesRuntimeVersion. The value is a string that represents the runtime version.

+ <key>EXUpdatesRuntimeVersion</key>
+ <string>1.0.0</string>

对于 Android 构建,请向 android/app/src/main/res/values/strings.xml 添加一个名为 expo_runtime_version 的条目。该值是表示运行时版本的字符串。

¥For an Android build, add an entry to android/app/src/main/res/values/strings.xml with the name expo_runtime_version. The value is a string that represents the runtime version.

然后在 AndroidManifest.xml 中添加一个 <meta-data> 元素,其 android:name 属性为 expo.modules.updates.EXPO_RUNTIME_VERSIONandroid:value 属性是对 strings.xml 中运行时版本的引用。

¥Then add a <meta-data> element to the AndroidManifest.xml whose android:name attribute is expo.modules.updates.EXPO_RUNTIME_VERSION and android:value attribute is a reference to the runtime version in strings.xml.

+ <meta-data android:name="expo.modules.updates.EXPO_RUNTIME_VERSION" android:value="@string/expo_runtime_version"/>

常见问题

¥FAQ

我可以在 Android 和 iOS 上使用不同的运行时版本吗?

¥Can I have a different runtime version on Android and iOS?

是的,如果你希望能够在平台级别控制运行时版本,你可以:

¥Yes, if you want to be able to control the runtime version on a platform level, you can:

  1. 拥有特定于平台的渠道:android-productionios-production

    ¥Have platform-specific channels: android-production, ios-production.

  2. 具有特定于平台的运行时版本:android-1.0.0ios-1.0.0

    ¥Have platform-specific runtime versions: android-1.0.0, ios-1.0.0.

但是,你不能设置特定于平台的配置字段,例如 android.runtimeVersionios.runtimeVersion

¥However, you cannot set a platform-specific configuration field such as android.runtimeVersion or ios.runtimeVersion

我可以在 Expo Go 上使用自定义运行时版本测试更新吗?

¥Can I test updates with a custom runtime version on Expo Go?

Expo Go 适用于针对 Expo SDK 的更新。如果你想测试针对自定义运行时版本的更新,你应该使用 开发构建

¥Expo Go is meant for updates targeting an Expo SDK. If you want to test an update targeting a custom runtime version, you should use a development build.

Expo 中文网 - 粤ICP备13048890号