首页指南参考教程

与你的团队分享预览

了解如何使用 EAS 更新发送 OTA 更新并与团队共享预览。


更新通常会修复小错误并在应用商店版本之间推送小更改。它们允许更新示例应用的非原生部分,例如 JavaScript 代码、样式和图片。

¥Updates generally fix small bugs and push small changes in between app store releases. They allow updating the non-native parts of our example app, such as JavaScript code, styling, and images.

在本章中,我们将使用 EAS 更新 与我们的团队共享更改。这将有助于 我们和我们的团队快速分享预览 的改变。

¥In this chapter, we'll use EAS Update to share changes with our team. This will help us and our team quickly share previews of the change.

1

安装 expo-updates 库

¥Install expo-updates library

要初始化我们的项目并发送更新,我们需要使用 expo-updates 库。运行以下命令来安装它:

¥To initialize our project and send an update, we need to use the expo-updates library. Run the following command to install it:

Terminal
npx expo install expo-updates

2

配置 EAS 更新

¥Configure EAS Update

要使用 EAS 更新初始化我们的项目,我们需要执行以下步骤:

¥To initialize our project with EAS Update, we need to follow these steps:

  • 由于我们使用动态 app.config.js 进行应用配置,因此需要添加 updatesruntimeVersion 属性以使我们的项目与 EAS 更新兼容。运行以下命令从 EAS 获取这些属性及其值,并手动将它们复制到 app.config.js:

    ¥Since we are using dynamic app.config.js for our app's configuration, adding updates and runtimeVersion properties are required to make our project compatible with EAS Update. Run the following command to obtain these properties and their values from EAS and manually copy them to app.config.js:

Terminal
eas update:configure
What about non-dynamic (app.json) projects?

如果项目不使用动态应用配置(使用 app.json 而不是 app.config.js),上述命令将配置我们的应用以与 EAS 更新兼容,并将正确的属性添加到 app.json 和 eas.json 。

¥If a project doesn't use dynamic app config (uses app.json instead of app.config.js), the above command will configure our app to be compatible with EAS Update and add the right properties to app.json and eas.json.

  • 重新运行 eas update:configure 以继续设置过程。应将 channel 添加到 eas.json 中的每个构建配置文件中:

    ¥Re-run eas update:configure to continue with the setup process. A channel should be added to every build profile in eas.json:

eas.json
{
  "build": {
    "development": {
      %%placeholder-start%%... %%placeholder-end%%
      "channel": "development"
    },
    "ios-simulator": {
      %%placeholder-start%%... %%placeholder-end%%
    },
    "preview": {
      %%placeholder-start%%... %%placeholder-end%%
      "channel": "preview"
    },
    "production": {
      %%placeholder-start%%... %%placeholder-end%%
      "channel": "production"
    }
  }
  %%placeholder-start%%... %%placeholder-end%%
}
请注意,eas update:configure 命令将 channel 添加到 eas.json 中的每个构建配置文件中。然而,我们的 ios-simulator 配置文件扩展了 development 配置文件,拥有单独的 channel 没有意义。我们可以安全地从上述配置中删除 ios-simulator.channel
What is a channel?

渠道 用于将构建分组在一起。如果我们在应用商店上有 Android 和 iOS 版本,我们可以为它们提供一个生产渠道。稍后,我们可以告诉 EAS Update 以生产通道为目标,因此我们的更新将影响具有生产通道的所有构建。

¥Channels are used to group builds together. If we have an Android and iOS build, both on the app store, we can give them both a channel of production. Later, we can tell EAS Update to target the production channel, so our update will affect all builds with a production channel.

3

创建开发版本

¥Create a development build

我们需要创建一个新的开发版本,因为我们的上一个版本不包含 expo-updates 库。运行以下命令:

¥We need to create a new development build since our last build doesn't contain the expo-updates library. Run the following command:

Terminal
eas build --platform android --profile development

我们正在使用 Android 设备的开发版本来演示更新。但是,我们可以使用 --platform all--platform ios 为两个平台或仅为 iOS 创建构建。

¥We are using a development build for Android devices to demonstrate updates. However, we can use --platform all or --platform ios to create a build for both platforms or just for iOS.

创建新版本的开发版本后,请确保将其安装在设备上。

¥After the new version of the development build is created, make sure to install it on a device.

4

修改应用的 JavaScript 代码

¥Modify the JavaScript code of the app

让我们修改示例应用的 JavaScript 代码。如果你没有使用 贴纸粉碎应用,你可以修改任何代码片段以查看应用中的更改。

¥Let's modify our example app's JavaScript code. If you are not using Sticker Smash app, you can modify any piece of your code to see the changes in the app.

我们将修改示例应用中第一个按钮的文本,即“选择照片”以选择照片。

¥We'll modify the text of the first button in our example app that says Choose a photo to Select a photo.

App.js
<Button theme="primary" label="Select a photo" onPress={pickImageAsync} />

5

发布更新

¥Publish an update

让我们发布一个更新,而不是创建一个新的版本来与我们的团队共享此更改以进行测试:

¥Instead of creating a new build to share this change with our team for testing, let's publish an update:

Terminal
eas update --branch development --message "Change first button label"

在上面的命令中,我们使用了 development 分支。每个更新都与 更新分支 相关联。它类似于我们使用 git 进行的每次提交,都与 git 分支相关联。

¥In the command above, we used the development branch. Every update is associated with an update branch. It is similar to every commit that we make with git, which is associated with a git branch.

默认情况下,如果未指定其他映射,EAS 将映射具有相同名称的分支和通道。因此,通过在我们的构建配置文件中使用通道 development,然后在开发分支上发布更新,我们要求 EAS 将此更新传递到使用 development 通道的构建。当我们创建 EAS 更新分支时,我们可以将其映射到通道。

¥By default, EAS will map branches and channels with the same name, if no other mapping has been specified. So, by using the channel development in our build profile and then publishing an update on the development branch, we're asking EAS to deliver this update to builds with the development channel. When we make an EAS Update branch, we can map it to a channel.

更新发布后,CLI 将提示我们相关信息。

¥After the update is published, the CLI will prompt us with information about it.

单击网站链接可在“更新”下查看 Expo 仪表板上的更新:

¥Click on the Website link to see the Update on the Expo dashboard under Updates:

6

在开发版本中实时预览更新

¥Preview the update live in a development build

要预览开发版本中的实时更新:

¥To preview the live update in a development build:

  • 在开发版本中登录你的 Expo 账户。

    ¥Log in to your Expo account within the development build.

  • 打开扩展选项卡。

    ¥Open the Extensions tab.

  • 寻找分行:开发列在 EAS 更新下。

    ¥Look for Branch: development listed under EAS Update.

  • 点击“打开”即可访问更新。

    ¥Tap on Open to access the update.

7

与预览或生产版本共享更改

¥Sharing changes with preview or production builds

当应用启动并请求任何新更新时,非开发版本(预览或生产)的更新会自动下载到设备。

¥Updates for non-development builds (preview or production) are automatically downloaded to the device when the app starts up and makes a request for any new updates.

任何运行预览或生产版本的团队成员都将收到我们推送到这些特定分支的更改的更新。

¥Any team member running the preview or production build will receive the update with the changes we push to those specific branches.

例如,对于 preview 构建,我们可以运行:

¥For example, for a preview build, we can run:

Terminal
eas update --branch preview --message "Change first button label"

以下是我们发布 preview 版本更新的示例。要测试更新,请强制关闭并重新打开应用两次以下载并查看更改:

¥Here is an example where we've published an update for the preview build. To test the update, force close and reopen the app twice to download and view the changes:

概括

¥Summary

Chapter 10: Share previews with your team

We successfully configured EAS Update to manage and publish over-the-air updates across platforms, and explored methods to fetch updates to review.

In the next chapter, learn about the process of triggering builds from a GitHub repository.

Next: Trigger builds from a GitHub repository
Expo 中文网 - 粤ICP备13048890号