开始使用 EAS 更新

了解如何开始在项目中配置和使用 EAS Update 所需的设置。


通过设置 EAS 更新,你可以立即推送用户需要的关键错误修复和改进。本指南将引导你完成在新项目或现有项目中设置 EAS 更新的过程。

¥Setting up EAS Update allows you to push critical bug fixes and improvements that your users need right away. This guide will walk you through the process of setting up EAS Update in a new or existing project.

如果你计划将 EAS Update 与 EAS Build 结合使用,我们建议你在继续此处之前先遵循 EAS Build 设置指南。也就是说,你可以在没有任何其他 EAS 服务的情况下使用 EAS 更新

先决条件

¥Prerequisites

An Expo user account

EAS 更新可供任何拥有 Expo 账户的人使用,无论你是支付 EAS 费用还是使用免费计划。你可以在 expo.dev/signup 报名。

¥EAS Update is available to anyone with an Expo account, regardless of whether you pay for EAS or use the Free plan. You can sign up at expo.dev/signup.

付费订阅者可以向更多用户发布更新,并使用更多带宽和存储空间。在 电子防盗系统定价 了解有关不同计划和福利的更多信息。

¥Paid subscribers can publish updates to more users and use more bandwidth and storage. Learn more about different plans and benefits at EAS pricing.

A React Native project

还没有项目吗?没问题。通过本指南可以快速轻松地创建 "你好世界" 应用。

¥Don't have a project yet? No problem. It's quick and easy to create a "Hello world" app that you can use with this guide.

运行以下命令创建一个新项目:

¥Run the following command to create a new project:

Terminal
npx create-expo-app my-app

EAS 更新还可以很好地与由 npx create-react-native-appnpx react-nativeignite-cli 和其他项目引导工具创建的项目配合使用。

¥EAS Update also works well with projects created by npx create-react-native-app, npx react-native, ignite-cli, and other project bootstrapping tools.

Your project must use Expo CLI and extend the Expo Metro Config

如果你已经使用 npx expo [command] 运行你的项目(例如,如果你使用 npx create-expo-app 创建它),那么你就一切就绪了。

¥If you already run your project with npx expo [command] (for example, if you created it with npx create-expo-app) then you're all set.

如果你的项目中还没有 expo 包,请通过运行以下命令和 选择使用 Expo CLI 和 Metro Config 来安装它:

¥If you don't have the expo package in your project yet, then install it by running the command below and opt in to using Expo CLI and Metro Config:

Terminal
npx install-expo-modules@latest

如果命令失败,请参阅 安装 Expo 模块 指南。

¥If the command fails, refer to the Installing Expo modules guide.

1

安装最新的 EAS CLI

¥Install the latest EAS CLI

EAS CLI 是命令行应用,你将使用它从终端与 EAS 服务进行交互。要安装它,请运行命令:

¥EAS CLI is the command line app you will use to interact with EAS services from your terminal. To install it, run the command:

Terminal
npm install --global eas-cli

你还可以使用上述命令检查是否有新版本的 EAS CLI 可用。我们鼓励你始终保持最新版本。

¥You can also use the above command to check if a new version of EAS CLI is available. We encourage you to always stay up to date with the latest version.

我们建议使用 npm 而不是 yarn 进行全局包安装。你也可以使用 npx eas-cli@latest。请记住,只要文档中需要它,就使用它而不是 eas

¥We recommend using npm instead of yarn for global package installations. You may alternatively use npx eas-cli@latest. Remember to use that instead of eas whenever it's called for in the documentation.

2

登录你的 Expo 账户

¥Log in to your Expo account

如果你已使用 Expo CLI 登录 Expo 账户,则可以跳过本节中描述的步骤。如果没有,请运行以下命令登录:

¥If you are already signed in to an Expo account using Expo CLI, you can skip the steps described in this section. If you are not, run the following command to log in:

Terminal
eas login

你可以通过运行 eas whoami 来检查你是否已登录。

¥You can check whether you are logged in by running eas whoami.

3

配置你的项目

¥Configure your project

在终端中导航到你的项目目录并运行以下命令:

¥Navigate to your project directory in your terminal and run the following command:

Terminal
# Initialize your project with EAS Update
eas update:configure
What does this command do?

eas update:configure 命令将使用 runtimeVersionupdates.url 属性更新你的 app.json 文件,如果你的项目以前没有使用任何 EAS 服务,则添加 extra.eas.projectId 字段。

¥The eas update:configure command will update your app.json file with the runtimeVersion and updates.url properties, and add the extra.eas.projectId field if your project wasn't using any EAS services previously.

当你在未使用 CNG 的项目中运行 eas update:configure 时,你将看到原生项目的以下更改:

¥When you run eas update:configure in a project that doesn't use CNG, you'll see the following changes to your native projects:

安卓

¥Android

在 android/app/src/main/AndroidManifest.xml 文件中,你将看到以下附加内容:

¥Inside the android/app/src/main/AndroidManifest.xml file, you'll see the following additions:

android/app/src/main/AndroidManifest.xml
<meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://u.expo.dev/your-project-id"/>
<meta-data android:name="expo.modules.updates.EXPO_RUNTIME_VERSION" android:value="@string/expo_runtime_version"/>

EXPO_UPDATE_URL 值应包含你的项目 ID。

¥The EXPO_UPDATE_URL value should contain your project's ID.

在 android/app/src/main/res/values/strings.xml 中,你将在 resources 对象中看到 expo_runtime_version 字符串条目:

¥Inside android/app/src/main/res/values/strings.xml, you'll see the expo_runtime_version string entry in the resources object:

iOS 系统

¥iOS

在 ios/project-name/Supporting/Expo.plist 内,你将看到以下添加内容:

¥Inside ios/project-name/Supporting/Expo.plist, you'll see the following additions:

ios/project-name/Supporting/Expo.plist
<key>EXUpdatesRuntimeVersion</key>
<string>1.0.0</string>
<key>EXUpdatesURL</key>
<string>https://u.expo.dev/your-project-id</string>

EXUpdatesURL 值应包含你的项目 ID。

¥The EXUpdatesURL value should contain your project's ID.

4

配置更新渠道

¥Configure the update channel

构建上的通道属性允许你将更新指向特定类型的构建。例如,它允许你将更新发布到预览版本而不会影响你的生产部署。

¥The channel property on a build allows you to point updates at specific types of builds. For example, it allows you to publish updates to a preview build without impacting your production deployment.

如果你使用 EAS Build,eas update:configure 将在 eas.json 中的 previewproduction 配置文件上设置更新 channel 属性。如果你使用不同的配置文件名称,请手动设置它们。

¥If you are using EAS Build, eas update:configure will set the update channel property on the preview and production profiles in eas.json. Set them manually if you use different profile names.

Example channel configuration in eas.json
eas.json
{
"build": {
  "preview": {
    "channel": "preview"
    // ...
  },
  "production": {
    "channel": "production"
    // ...
  }
}
}

如果你不使用 EAS Build,则需要在 app.json 或原生项目中配置渠道,具体取决于你是否使用 CNG。当你为不同的环境创建构建时,你需要修改渠道以确保你的构建从正确的渠道提取更新。使用 EAS 更新作为独立服务 了解更多信息。

¥If you are not using EAS Build, then you will need to configure the channel in app.json or in your native projects, depending on whether you use CNG. When you create a build for a different environment, you will need to modify the channel to ensure your build pulls updates from the correct channel. Learn more using EAS Update as a standalone service.

Configure update channels in app.json

如果你使用持续原生生成 (CNG),则可以使用 app.json 中的 updates.requestHeaders 属性配置渠道:

¥If you use Continuous Native Generation (CNG), then you can configure the channel with the updates.requestHeaders property in your app.json:

app.json
{
"expo": {
  %%placeholder-start%%... %%placeholder-end%%
  "updates": {
    %%placeholder-start%%... %%placeholder-end%%
    "requestHeaders": {
      "expo-channel-name": "your-channel-name"
    }
    %%placeholder-start%%... %%placeholder-end%%
  }
  %%placeholder-start%%... %%placeholder-end%%
}
}

下次运行 npx expo prebuild 时将应用配置。

¥The configuration will be applied the next time you run npx expo prebuild.

Configure update channels in an Android native project

在 AndroidManifest.xml 中,你需要添加替换 your-channel-name 以使用与你的项目匹配的渠道:

¥In AndroidManifest.xml, you will need to add replace your-channel-name with the channel that matches your project:

android/app/src/main/AndroidManifest.xml
<meta-data android:name="expo.modules.updates.UPDATES_CONFIGURATION_REQUEST_HEADERS_KEY" android:value="{&quot;expo-channel-name&quot;:&quot;your-channel-name&quot;}"/>
Configure update channels in an iOS native project

在 Expo.plist 中,你需要添加以下内容,将 your-channel-name 替换为与你的项目匹配的通道:

¥In Expo.plist, you'll need to add the following, replacing your-channel-name with the channel that matches your project:

ios/project-name/Supporting/Expo.plist
<key>EXUpdatesRequestHeaders</key>
<dict>
<key>expo-channel-name</key>
<string>your-channel-name</string>
</dict>

5

为项目创建一个构建

¥Create a build for the project

你需要创建适用于 Android 或 iOS 的版本。我们建议首先使用 preview 构建配置文件创建构建。请参阅 创建你的第一个版本,了解如何开始使用并为你的设备或模拟器设置 内部分发

¥You need to create a build for Android or iOS. We recommend creating a build with the preview build profile first. See Create your first build on how to get started and set up Internal distribution for your device or simulator.

一旦你的设备或模拟器上运行了构建版本,你就可以发送更新了。

¥Once you have a build running on your device or a simulator, you are ready to send an update.

6

在本地进行更改

¥Make changes locally

创建构建后,你就可以迭代项目了。使用以下命令启动本地开发服务器:

¥After creating the build, you are ready to iterate on the project. Start a local development server with the following command:

Terminal
npx expo start

然后,对项目的 JavaScript、样式或图片资源进行所需的更改。

¥Then, make any desired changes to your project's JavaScript, styling, or image assets.

7

发布更新

¥Publish an update

发布更新允许:

¥Publishing an update allows:

要发布包含项目更改的更新,请使用 eas update 命令,并指定通道名称和 message 来描述更新:

¥To publish an update with changes from your project, use the eas update command, and specify a name for the channel and a message to describe the update:

Terminal
eas update --channel [channel-name] --message "[message]"
How does publishing an update work?

当你使用 eas update 命令发布更新时,它会生成一个新的更新包并将其上传到 EAS 服务器。通道名称用于定位正确的分支以从其他更新分支发布新更新。它类似于 Git 提交的工作方式,每个提交都在 Git 分支上。

¥When you publish an update with the eas update command, it generates a new update bundle and uploads it to the EAS servers. The channel name is used to locate the correct branch to publish a new update from other update branches. It is similar to how Git commit works, where every commit is on a Git branch.

例如,当应用设置为从 preview 通道提取更新时,你可以使用 eas update --channel preview 发布该版本的更新。这将在 preview 通道上创建一个分支(默认称为 preview)。在后台,此命令运行 npx expo export 以生成 dist 目录并创建本地更新包。此更新包已上传到 EAS 更新服务器。

¥For example, when an app is set to pull updates from the preview channel, you can publish an update for that build with eas update --channel preview. This will create a branch (called preview by default) on the preview channel. Behind the scenes, this command runs npx expo export to generate a dist directory and create a local update bundle. This update bundle is uploaded to EAS Update servers.

EAS 更新工作原理的深入指南

深入了解并了解 EAS 更新的工作原理。

8

测试本地

¥Test the update

将更新上传到 EAS Update 后,你可以使用以下方法之一来测试更新:

¥After the update is uploaded to EAS Update, you can use one of the following methods to test the update:

  • 使用 开发构建 中的扩展选项卡加载更新。

    ¥Use the Extensions tab in a development build to load the update.

  • 使用 Expo 轨道 在开发版本中安装和启动更新。

    ¥Use Expo Orbit to install and launch the update in a development build.

  • 使用 更新 API应用配置 实现自定义策略,以编程方式在应用中加载更新。

    ¥Implement a custom strategy with Updates API and app config to load updates in the app programmatically.

  • 通过强制关闭并重新打开应用的发布版本最多两次来下载和应用更新,手动测试更新。当应用启动并请求任何新更新时,非开发版本(预览或生产)的更新会在后台自动下载到设备。下载更新并重新启动应用后,将应用更新。

    ¥Manually test the update by force closing and reopening a release build of your app up to two times to download and apply the update. Updates for non-development builds (preview or production) are automatically downloaded to the device in the background when the app starts up and makes a request for any new updates. The update will be applied after it is downloaded and the app is restarted.

Something not working?

如果你的应用未按预期更新,请参阅 调试指南 以了解验证配置的技术。

¥If your app is not updating as expected, see the debugging guide for techniques to validate your configuration.

下一步

¥Next steps

本地生产版本

了解如何通过共享更新进行 QA 和测试来快速迭代。

部署更新

了解使用 EAS 更新时项目的不同部署模式。