与你的团队分享预览

了解如何使用 EAS Update 发送 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 Update 与团队分享更改。这将帮助 我们和团队快速分享更改的预览

🌐 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 Update 初始化我们的项目,我们需要按照以下步骤操作:

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

  • 由于我们正在使用动态 app.config.js 来配置我们的应用,因此需要添加 updatesruntimeVersion 属性,以使我们的项目兼容 EAS Update。运行以下命令从 EAS 获取这些属性及其值,并手动将它们复制到 app.config.js 中:
Terminal
eas update:configure
非动态(app.json)项目怎么样?

如果一个项目不使用动态应用配置(使用 app.json 而不是 app.config.js),上述命令将配置我们的应用以兼容 EAS Update,并向 app.jsoneas.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 以继续设置过程。每个 eas.json 中的构建配置文件都应添加 channel
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

什么是通道?

通道 用于将构建分组。如果我们有一个 Android 构建和一个 iOS 构建,并且它们都在应用商店中,我们可以给它们都指定一个生产通道。之后,我们可以告诉 EAS Update 以生产通道为目标,这样我们的更新将影响所有拥有生产通道的构建。

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

我们正在使用针对安卓设备的开发版本来演示更新。不过,我们可以使用 --platform all--platform ios 来创建适用于两个平台或仅适用于 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 代码。如果你没有使用 Sticker Smash 应用,你也可以修改你代码中的任何部分来查看应用中的更改。

🌐 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/(tabs)/index.tsx
<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 --channel development --message "Change first button label"

在上面的命令中,我们使用了 development 通道。每次更新都与一个 通道名称 相关联。它类似于我们使用 git 所做的每次提交,每次提交都关联一个 git 分支。

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

因此,通过在我们的构建配置中使用 development 渠道,然后发布更新,我们要求 EAS 将此更新发布到具有 development 渠道的构建。当我们创建一个 EAS 更新渠道时,它会自动映射到具有相同名称的分支。

🌐 So, by using the channel development in our build profile and then publishing an, we're asking EAS to deliver this update to builds with the development channel. When we make an EAS Update channel it automatically gets mapped to a branch with the same name.

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

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

点击 网站链接 查看 EAS 仪表板中 空中更新 > 更新组 下的更新内容:

🌐 Click on the Website link to see the Update on the EAS dashboard under Over-the-air updates > Update groups:

6

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

🌐 Preview the update live in a development build

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

🌐 To preview the live update in a development build:

  • 在开发构建中登录你的 Expo 账户。
  • 打开 扩展 标签。
  • EAS 更新 下查找列为 Branch: development 的项。
  • 点击 打开 以访问更新。

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 --channel 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

我们成功配置了 EAS Update,以管理和发布跨平台的空中更新,并探索了获取更新以进行查看的方法。

在下一章中,了解如何从 GitHub 仓库触发构建的过程。

Next: 从 GitHub 存储库触发构建