从 CodePush 迁移
帮助从 CodePush 迁移到 EAS 更新的指南。
本指南介绍了如何将使用 CodePush 的 React Native 项目转换为使用提供 许多优点 的 EAS 更新。它假设你使用默认的 React Native 项目结构。如需将棕地原生应用迁移到 EAS 更新的帮助,直接联系我们。
¥This guide explains how to transition a React Native project that uses CodePush to use EAS Update which offers many advantages. It assumes that you're using the default React Native project structure. For assistance with migrating brownfield native apps to EAS Update, reach out to us directly.
要了解有关 CodePush 和 EAS Update 之间的区别的更多信息,请参阅 CodePush 和 EAS Update 之间的概念差异 和 Expo 博客上没有 CodePush 帖子怎么办。
¥To learn more about the differences between CodePush and EAS Update, see Conceptual differences between CodePush and EAS Update and the What to do without CodePush post on the Expo Blog.
1
卸载代码推送
¥Uninstall CodePush
为了避免冲突和意外行为,如果你使用 EAS 更新,建议卸载 CodePush。这是因为你的应用可能会定期从这两个服务获取更新,从而导致问题,特别是当你为每个服务使用不同的配置时。
¥To avoid conflicts and unexpected behavior, it's recommended to uninstall CodePush if you're using EAS Update. This is because your app could periodically fetch updates from both services, leading to issues, especially if you're using different configurations for each service.
通过卸载 react-native-code-push
包从项目中删除 CodePush SDK:
¥Remove the CodePush SDK from your project by uninstalling the react-native-code-push
package:
-
npm uninstall react-native-code-push
你还需要从 JS 和原生代码中删除 CodePush 引用。请参阅此 GitHub 评论,了解更详细的说明。
¥You'll also need to remove CodePush references from JS and native code. See this GitHub comment for more detailed instructions.
2
将 expo
密钥添加到你的 app.json
¥Add an expo
key to your app.json
确保你的项目有一个带有 expo
对象的 app.json 文件。如果你的 app.json 文件中还没有任何特定内容需要配置,则可以创建一个包含空 expo
对象的最小文件,如下所示:
¥Ensure that your project has an app.json file with an expo
object. If you don't have anything specific to configure in your app.json file yet, you can create a minimal file with an empty expo
object like this:
{
"expo": {
//... any other existing keys you have
}
}
3
遵循 "入门" 指南
¥Follow the "Getting Started" guide
EAS 更新入门指南 中的说明将指导你在项目中设置 EAS 更新。
¥The instructions in the EAS Update Getting Started guide will guide you through setting up EAS Update in your project.
4
可重复使用的转换记忆化
¥Resubmit your app
由于你已将更新提供程序从 CodePush 更改为 EAS Update,因此你需要重建你的应用并将新版本提交到相应的应用商店(Google Play Store 和 Apple App Store),以确保更新机制按预期为你的终端用户工作。
¥Since you have changed the update provider from CodePush to EAS Update, you will need to rebuild your app and submit the new build to the respective app stores (Google Play Store and Apple App Store) to ensure the update mechanism works as expected for your end-users.
请遵循相应的商店指南来提交应用的新版本:
¥Follow the respective store guidelines for submitting a new build of your application:
成功提交应用后,用户将能够下载并使用集成 EAS 更新的最新版本。如果你的应用未按预期更新,验证你的配置。
¥After successfully submitting your app, users will be able to download and use the latest build with EAS Update integration. If your app is not updating as expected, validate your configuration.
CodePush 和 EAS Update 之间的概念差异
¥Conceptual differences between CodePush and EAS Update
CodePush 和 EAS Update 都是允许你将修补程序发送到应用的 JavaScript 代码的服务,但它们需要方法略有不同,因此你可能需要在迁移到 EAS 更新时调整发布流程。
¥CodePush and EAS Update are both services that allow you to send hotfixes to the JavaScript code of your app, but they take slightly different approaches, and so you may need to adapt your release process when moving to EAS Update.
Differences in how updates are organized within streams
CodePush 具有用于部署的单一更新流。这意味着你可以将构建指向部署,它将从中提取更新。如果你想更改构建所针对的部署,你可以在运行时通过 JavaScript API 执行此操作。
¥CodePush has single streams of updates for deployments. What this means is that you can point a build to a deployment, and it will pull updates from that. If you want to change the deployment that is targeted by a build, you can do this at runtime through a JavaScript API.
EAS 更新有多个更新流 - 一个对应于你的源代码控制分支(称为分支),另一个称为渠道,指向分支。渠道和分支之间的映射在服务器端处理,并且渠道可以指向每个运行时版本的不同分支(此外,还可以表达更高级的逻辑,例如支持增量推出)。构建不直接与分支相关联,而是与渠道相关联。每个构建都指向一个通道,该通道在构建时设置,无法在运行时修改。这样做的原因是,它确保某些分支(例如:开发、暂存)不会自动进入生产环境 — 你的预览更新不会发送给你的生产用户。这可以帮助你区分 EAS 更新的两个主要用途:预览和生产修补程序。
¥EAS Update has multiple streams of updates — one that correspond to your source control branches (called branches), and another called channels, which point to branches. The mapping between channels and branches is handled on the server side, and a channel can point to different branches for each runtime version (additionally, more advanced logic may be expressed, such as to support incremental rollouts). Builds are not directly associated with branches, but rather with channels. Each build points to a single channel, which is set at build time and cannot be modified at runtime. The reason for this is that it ensures that certain branches (eg: development, staging) don't automatically go out to production — your preview updates don't go to your production users. This helps you separate the two main uses of EAS Update: previews and production hotfixes.
Differences in how updates are selected at runtime
CodePush 和 EAS Update 之间的一个主要区别可能会影响你的发布过程,即使用 CodePush,客户端在运行时控制目标更新部署,而使用 EAS Update,它通过将渠道映射到分支在服务器端进行控制。这意味着你无法使用 EAS Update 在你的应用中包含代码来指示它根据运行时条件(例如当前用户角色(例如:将测试版分发给员工))加载不同的更新流 - 它只会将映射到 EAS 更新服务器上的分支加载到相应的渠道(例如生产或暂存)。
¥A key distinction between CodePush and EAS Update that can impact your release process is that with CodePush, the client controls the target update deployment at runtime, and with EAS Update, it is controlled on the server side, by mapping channels to branches. This means that you can't include code in your app using EAS Update to instruct it to load a different stream of updates depending on runtime criteria, such as the current user role (eg: distribute beta releases to employees) - it will only load the branch that is mapped on EAS Update servers to the corresponding channel (such as production or staging).
在运行时控制目标部署的能力通常与 CodePush 在暂存环境中一起使用,以允许非技术利益相关者在 Google Play Beta/TestFlight 上测试单个构建中的功能。EAS 更新的当前替代方案是使用 开发构建。我们目前正在努力提供一种使用发布版本来实现此目的的方法。
¥The ability to control the target deployment at runtime is commonly used with CodePush in staging environments to allow non-technical stakeholders to test features from a single build on Google Play Beta / TestFlight. The current alternative for this with EAS Update is to use development builds. We're currently working on providing a way to do this with release builds.