首页指南参考教程

即时更新

了解如何设置 EAS 更新以推送关键错误修复和改进。


EAS 更新允许修复小错误并快速推动改进。它是一项使用 expo-updates 库来提供更新的托管服务。它允许终端用户的应用将其应用的非原生部分(例如,JS、样式和图片更改)替换为包含错误修复和其他更新的新更新。在本指南中,你将了解如何为你的应用设置 EAS 更新。

¥EAS Update allows making small bug fixes and pushing quick improvements in a snap. It is a hosted service that uses the expo-updates library to serve updates. It allows an end user's app to swap out the non-native parts of their app (for example, JS, styling, and image changes) with a new update that contains bug fixes and other updates. In this guide, you will learn how to set up EAS Update for your app.

安装 expo-updates

¥Install expo-updates

首先在你的项目中安装 expo-updates 库。运行以下命令:

¥Start by installing the expo-updates library in your project. Run the following command:

Terminal
npx expo install expo-updates

使用 eas update 配置项目

¥Configure the project with eas update

你需要配置你的项目以使用 EAS 更新。按指定顺序运行以下命令:

¥You need to configure your project to use EAS Update. Run the following commands in the order they are specified:

Terminal
# Initialize your project with EAS Update
eas update:configure

# Set up the configuration file for builds
eas build:configure

运行这些命令后,项目根目录中的 eas.json 文件将被修改。在其中,你会发现 channel 属性已添加到 developmentpreviewproduction 构建配置文件中。

¥After running these commands, the eas.json file be modified in the root directory of your project. Inside it, you'll find that a channel property is added to the development, preview and production build profiles.

eas.json
{
  "build": {
    "development": {
      "channel": "development"
      %%placeholder-start%%... %%placeholder-end%%
    },
    "preview": {
      "channel": "preview"
      %%placeholder-start%%... %%placeholder-end%%
    },
    "production": {
      "channel": "production"
      %%placeholder-start%%... %%placeholder-end%%
    }
  }
}

channel 允许你将该配置文件的版本指向更新。例如,如果你设置 GitHub Action 来发布合并更改,它会将代码合并到 "production" Git 分支中。然后,每次提交都会触发一个 GitHub 操作,该操作将发布一个更新,该更新可用于通过通道 "production" 进行构建。

¥The channel allows you to point updates at builds of that profile. For example, if you set up a GitHub Action to publish changes on merge, it will merge code into the "production" Git branch. Then, each commit will trigger a GitHub Action that will publish an update which will be available to build with the channel "production".

为项目创建一个构建

¥Create a build for the project

对于 Android 或 iOS,你需要 创建一个构建。我们建议首先使用 preview 构建配置文件创建构建。这将允许你在将更新发布到 production 通道之前测试你的更新。

¥You need to create a build for Android or iOS. We recommend creating a build with the preview build profile first. This will allow you to test your update before publishing it to the production channel.

一旦你的设备或模拟器上运行了构建,你就可以迭代该项目了。对项目的 JavaScript、样式或图片资源进行任何所需的更改。

¥Once you have a build running on your device or a simulator, you are ready to iterate on the project. Make any desired changes to your project's JavaScript, styling, or image assets.

发布更新

¥Publish an update

要发布版本更新,请运行以下命令:

¥To publish an update to the build, run the following command:

Terminal
# eas update --branch [branch] --message [message]
# Example
eas update --branch preview --message "Updating the app"

构建更新并将其上传到 EAS 并且命令完成后,强制关闭并重新打开你的应用最多两次以下载和查看更新。

¥Once the update is built and uploaded to EAS and the command completes, force close and reopen your app up to two times to download and view the update.

下一步

¥Next step

EAS 更新的工作原理

EAS 更新工作原理的概念性概述。

Expo 中文网 - 粤ICP备13048890号