首页指南参考教程

从经典更新迁移

帮助从经典更新迁移到 EAS 更新的指南。


SDK 49 是支持经典更新的最后一个版本。要继续使用已弃用的 expo publish 命令,请在应用配置中设置 updates.useClassicUpdates

¥SDK 49 was the last version to support Classic Updates. To continue using the deprecated expo publish command, set updates.useClassicUpdates in your app config.

EAS Update 是 Expo 的下一代更新服务。如果你使用经典更新,本指南将帮助你升级到 EAS 更新。

¥EAS Update is the next generation of Expo's updates service. If you're using Classic Updates, this guide will help you upgrade to EAS Update.

先决条件

¥Prerequisites

EAS 更新需要以下版本或更高版本:

¥EAS Update requires the following versions or greater:

  • Expo CLI >= 5.3.0

  • EAS CLI >= 0.50.0

  • Expo SDK >= 45.0.0

  • expo-updates >= 0.13.0

安装 EAS CLI

¥Install EAS CLI

1

安装 EAS CLI:

¥Install EAS CLI:

Terminal
npm install --global eas-cli

2

然后,使用你的 Expo 账户登录:

¥Then, log in with your expo account:

Terminal
eas login

配置你的项目

¥Configure your project

你需要对项目进行以下更改:

¥You'll need to make the following changes to your project:

1

使用 EAS 更新初始化你的项目:

¥Initialize your project with EAS Update:

Terminal
eas update:configure

执行此命令后,你的应用配置中应该有两个新字段,分别为 expo.updates.urlexpo.runtimeVersion

¥After this command, you should have two new fields in your app config at expo.updates.url and expo.runtimeVersion.

2

为了确保更新与构建内的底层原生代码兼容,EAS 更新使用名为 runtimeVersion 的新字段来替换项目应用配置中的 sdkVersion 字段。从应用配置中删除 expo.sdkVersion 属性。

¥To ensure that updates are compatible with the underlying native code inside a build, EAS Update uses a new field named runtimeVersion that replaces the sdkVersion field in your project's app config. Remove the expo.sdkVersion property from your app config.

3

要允许更新应用于使用 EAS 构建的构建,请更新 eas.json 中的 EAS 构建配置文件以包含 channel 属性。这些通道取代了 releaseChannel 属性。我们发现以配置文件名称命名 channel 很方便。例如,preview 配置文件有一个名为 "preview"channelproduction 配置文件有一个名为 "production"channel

¥To allow updates to apply to builds built with EAS, update your EAS Build profiles in eas.json to include channel properties. These channels replace releaseChannel properties. We find it convenient to name the channel after the profile's name. For instance, the preview profile has a channel named "preview" and the production profile has a channel named "production".

eas.json
{
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "preview": {
      "distribution": "internal",
      "channel": "preview"
    },
    "production": {
      "channel": "production"
    }
  }
}

4

可选的:如果你的项目是一个裸露的 React Native 项目,请参阅 在现有项目中使用 EAS 更新 了解你可能需要的额外配置。

¥Optional: If your project is a bare React Native project, see Use EAS Update in an existing project for the extra configuration you may need.

创建新版本

¥Create new builds

上述更改会影响构建内的原生代码层,这意味着你需要进行新的构建才能开始发送更新。构建完成后,你就可以发布更新了。

¥The changes above affect the native code layer inside builds, which means you'll need to make new builds to start sending updates. Once your builds are complete, you'll be ready to publish an update.

发布更新

¥Publish an update

在本地对项目进行更改后,你就可以发布更新了,请运行:

¥After making a change to your project locally, you're ready to publish an update, run:

Terminal
eas update --channel [channel-name] --message [message]

# Example
eas update --channel production --message "Fixes typo"

发布后,你可以在 Expo 仪表板 中看到更新。

¥Once published, you can see the update in the Expo dashboard.

额外的迁移步骤

¥Additional migration steps

  • 将脚本中的 expo publish 实例替换为 eas update。你可以查看使用 eas update --help 发布的所有选项。

    ¥Replace instances of expo publish with eas update in scripts. You can view all the options for publishing with eas update --help.

  • 如果你有任何引用 expo-updates 库中的 Updates.releaseChannel 的代码,请将其替换为 Updates.channel

    ¥If you have any code that references Updates.releaseChannel from the expo-updates library, replace them with Updates.channel.

  • 删除所有引用 Constants.manifest 的代码。现在将始终返回 null。你可以从 expo-constants 库访问 Constants.expoConfig 所需的大多数属性。

    ¥Remove any code that references Constants.manifest. That will now always return null. You can access most properties you'll need with Constants.expoConfig from the expo-constants library.

了解更多

¥Learn more

上述步骤允许你使用与经典更新类似的流程。不过,EAS Update 更灵活,功能也更多。它可用于创建更稳定的发布流。了解 EAS 更新的工作原理 以及如何为你的项目和团队打造更稳定的 部署流程

¥The steps described above allow you to use a similar flow to Classic Updates. However, EAS Update is more flexible and has more features. It can be used to create more stable release flows. Learn how EAS Update works and how you can craft a more stable deployment process for your project and your team.

如果你在迁移时遇到问题,请查看我们的 调试指南。如果你有反馈意见,请在 Discord 的 #update 通道中加入我们。

¥If you experience issues with migrating, check out our debugging guide. If you have feedback, join us on Discord in the #update channel.

Expo 中文网 - 粤ICP备13048890号