发布渠道


本文档于 2022 年 8 月归档,将不再更新。想了解更多关于发布渠道被废弃的原因,请参考我们的EAS Update 博客文章。我们建议改用EAS Update

介绍

🌐 Introduction

在 Expo 中使用发布渠道,通过提供 URL 或配置独立应用,将应用的不同版本发送给用户。如果符合以下情况,你应使用发布渠道:

🌐 Use release channels in Expo to send out different versions of your application to your users by giving them a URL or configuring your standalone app. You should use release channels if:

  • 你有一个正在生产的应用,需要一个测试环境。
  • 你的应用有多个版本。

通过发布渠道发布

🌐 Publish with release channels

通过运行以下命令在发布通道上发布你的更新:

🌐 Publish your update on a release channel by running:

Terminal
# Publish to release channel <your-channel>
expo publish --release-channel <your-channel>

你的团队可以在 Expo Go 应用中通过带参数的 URL https://exp.host/@username/yourApp?release-channel=<your-release-channel> 查看此发布渠道。如果你没有指定发布渠道,你将发布到 default 渠道。

🌐 Your team can see this release channel in the Expo Go app with a parameterized URL https://exp.host/@username/yourApp?release-channel=<your-release-channel>. If you do not specify a release channel, you will publish to the default channel.

发布通道名称只能包含小写字母、数字和特殊字符 ._-

🌐 A release channel name can only contain lowercase letters, numbers and special characters ., _ and -.

使用发布渠道进行构建

🌐 Build with release channels

eas.json 的构建配置中设置你的发布渠道:

🌐 Set your release channel in the build profile in eas.json:

{ "build": { "your-build-profile": { "releaseChannel": "your-channel" } } }

然后,通过使用 EAS CLI 运行 eas build --profile <your-build-profile> 来构建你的独立应用。生成的二进制文件将只拉取在指定发布渠道下发布的版本。如果你未指定发布渠道,二进制文件将从 default 发布渠道拉取版本。

🌐 Then, build your standalone app by running eas build --profile <your-build-profile> with the EAS CLI. The binary produced will only pull releases published under the specified release channel. If you do not specify a release channel, your binary will pull releases from the default release channel.

从代码访问通道

🌐 Access channel from code

你可以通过 expo-updatesUpdates.releaseChannel 字段访问你的更新发布的版本通道。

🌐 You can access the release channel your update is published under with the Updates.releaseChannel field from expo-updates.

在 Expo Go 开发中,Updates.releaseChannel 总是 'default'

工作流程示例

🌐 Example workflow

考虑这样一种情况,你有一个用于在 Expo Go 上进行测试的暂存堆栈,以及一个用于推送 TestFlight 的生产堆栈,然后推广到 App Store。

🌐 Consider a situation where you have a Staging stack for testing on Expo Go, and a Production stack for pushing through TestFlight, then promoting to the App Store.

在预发布环境的堆栈上,运行 expo publish --release-channel staging。你的测试用户可以通过在 URL 的查询参数中指定发布渠道(即 https://exp.host/@username/yourApp?release-channel=staging),然后在他们的网页浏览器中打开该 URL,并最终使用 Expo Go 应用扫描二维码,从而看到你的应用的预发布版本。或者,他们也可以直接在移动设备上打开该 URL。

🌐 On the staging stack, run expo publish --release-channel staging. Your test users can see the staging version of your app by specifying the release channel in the query parameter of the URL (ie)https://exp.host/@username/yourApp?release-channel=staging, then opening the URL in their web browser, and finally scanning the QR code with the Expo Go app. Alternatively, they can open that URL directly on their mobile device.

在生产环境中,通过运行 expo publish --release-channel prod-v1 来发布你应用的 v1 版本。你可以通过在 eas.jsonprod 构建配置中将 releaseChannel 设置为 prod-v1,然后运行 eas build --platform ios --profile prod,将此版本的应用构建为独立的 ipa 文件:

🌐 On the production stack, release v1 of your app by running expo publish --release-channel prod-v1. You can build this version of your app into a standalone ipa by running eas build --platform ios --profile prod with releaseChannel set to prod-v1 in the prod build profile in eas.json:

{ "build": { "prod": { "releaseChannel": "prod-v1" }, "staging": { "releaseChannel": "staging" } } }

你可以通过发布到 prod-v1 发布通道来推送应用更新。独立应用将会更新到 prod-v1 发布通道上与你的应用最兼容的最新版本。

🌐 You can push updates to your app by publishing to the prod-v1 release channel. The standalone app will update with the most recent compatible version of your app on the prod-v1 release channel.

如果你有一个新的版本,不想让 v1 用户获得,可以通过运行 expo publish --release-channel prod-v2 发布你的应用 v2,在你的 prod 构建配置中将 releaseChannel 设置为 prod-v2,然后再次使用 eas build --platform ios --profile prod 构建。只有拥有 prod-v2 ipa 的用户才会从该发布通道获取更新。

🌐 If you have a new version that you don't want v1 users getting, release v2 of your app by running expo publish --release-channel prod-v2, setting the releaseChannel in your prod build profile to prod-v2, and building again with eas build --platform ios --profile prod. Only users with the prod-v2 ipa will pull releases from that release channel.

你可以继续使用 expo publish --release-channel prod-v1 更新你应用的 v1 版本,而那些尚未在 Apple App Store 更新到最新 prod-v2 ipa 的用户将继续接收最新的 prod-v1 版本。

🌐 You can continue updating v1 of your app with expo publish --release-channel prod-v1, and users who haven't updated to the latest prod-v2 ipa in the Apple App Store will continue receiving the latest prod-v1 releases.

在裸工作流程中使用发布通道

🌐 Using release channels in the bare workflow

你可以通过修改 Expo.plist(iOS)中的 EXUpdatesReleaseChannel 键,或 AndroidManifest.xml(Android)中的 releaseChannel 元数据标签值,来编辑原生项目的发布渠道。阅读此指南 以了解有关在裸应用中配置更新的更多信息。

🌐 You can edit the native project's release channel by modifying the EXUpdatesReleaseChannel key in Expo.plist (iOS) or the releaseChannel meta-data tag value in AndroidManifest.xml (Android). Read this guide for more information on configuring updates in a bare app.

使用发布通道进行环境变量配置

🌐 Using release channels for Environment Variable configuration

环境变量并不明确存在,但你可以利用发布渠道来实现这一点!

🌐 Environment variables don't exist explicitly, but you can utilize release channels to make that happen!

假设你有一个发布构建的工作流程,如下所示:

🌐 Say you have a workflow of releasing builds like this:

Terminal
# Publish to release channel prod-v1expo publish --release-channel prod-v1
# Publish to release channel prod-v2expo publish --release-channel prod-v2
# Publish to release channel prod-v3expo publish --release-channel prod-v3

# Publish to release channel staging-v1expo publish --release-channel staging-v1
# Publish to release channel staging-v2expo publish --release-channel staging-v2

你可以创建一个函数来查找特定版本并相应地调整应用的行为:

🌐 You can create a function that looks for the specific release and adjust your app's behavior accordingly:

import * as Updates from 'expo-updates'; function getEnvironment() { if (Updates.releaseChannel.startsWith('prod')) { // matches prod-v1, prod-v2, prod-v3 return { envName: 'PRODUCTION', dbUrl: 'ccc', apiKey: 'ddd' }; // prod env settings } else if (Updates.releaseChannel.startsWith('staging')) { // matches staging-v1, staging-v2 return { envName: 'STAGING', dbUrl: 'eee', apiKey: 'fff' }; // stage env settings } else { // assume any other release channel is development return { envName: 'DEVELOPMENT', dbUrl: 'aaa', apiKey: 'bbb' }; // dev env settings } }