本文档于 2022 年 8 月存档,不会收到任何进一步更新。要了解有关为何弃用发布通道的更多信息,请参阅我们关于 EAS 更新的博客文章。相反,我们建议使用 EAS 更新。
¥This doc was archived in August 2022 and will not receive any further updates. To learn more about why release channels were deprecated, see our blog post on EAS Update. Instead, we recommend using 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:
你有一个正在生产的应用,需要一个测试环境。
¥You have an app in production and need a testing environment.
你的应用有多个版本。
¥You have multiple versions of your app.
¥Publish with release channels
通过运行以下命令在发布通道上发布你的更新:
¥Publish your update on a release channel by running:
# 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-updates 中的 Updates.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'
。¥In development in Expo Go,
Updates.releaseChannel
is always'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 (ie)https://exp.host/@username/yourApp?release-channel=staging
的查询参数中指定发布渠道,然后在 Web 浏览器中打开该 URL,最后使用 Expo Go 应用扫描 QR 码来查看应用的暂存版本。或者,他们可以直接在移动设备上打开该 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 build --platform ios --profile prod
并将 releaseChannel
设置为 prod-v1
(在 eas.json 的 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
、将 prod
构建配置文件中的 releaseChannel
设置为 prod-v2
,然后使用 eas build --platform ios --profile prod
再次构建来发布应用的 v2。只有拥有 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:
# Publish to release channel prod-v1
expo publish --release-channel prod-v1
# Publish to release channel prod-v2
expo publish --release-channel prod-v2
# Publish to release channel prod-v3
expo publish --release-channel prod-v3
# Publish to release channel staging-v1
expo publish --release-channel staging-v1
# Publish to release channel staging-v2
expo 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
}
}