从 CodePush 迁移
帮助从 CodePush 迁移到 EAS 更新的指南。
本指南解释了如何将使用 CodePush 的 React Native 项目过渡到使用 EAS Update,EAS Update 提供了许多优势。假设你正在使用默认的 React Native 项目结构。有关将棕地原生应用迁移到 EAS Update 的帮助,请参阅在现有原生应用中使用 EAS Update。
🌐 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, see Using EAS Update in an existing native app.
要了解 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
确保你的应用正在使用最新的 Expo SDK 版本
🌐 Ensure your app is using the latest Expo SDK version
要从 CodePush 迁移到 EAS Update,我们建议你使用最新的 Expo SDK 版本。对于较旧的 Expo SDK 和 React Native 版本,没有可用的操作说明。虽然你可以根据自己应用使用的较旧 Expo SDK 和 React Native 版本对说明进行相应调整,从而成功迁移,但对于与旧版本集成的额外实际操作支持,仅向企业客户提供(联系我们)。
🌐 To migrate from CodePush to EAS Update, we recommend that you use the latest Expo SDK version. Instructions are not available for older Expo SDK and React Native version. While you may be able to migrate successfully by adapting the instructions as needed for the older Expo SDK and React Native version that your app uses, additional hands-on support for integrating with older versions can only be provided for enterprise customers (contact us).
2
卸载 CodePush
🌐 Uninstall CodePush
为了避免冲突和意外行为,如果你正在使用 EAS Update,建议卸载 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.
3
在你的 app.json 中添加一个 expo 键
🌐 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 } }
4
请按照“入门指南”操作
🌐 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.
5
重新提交你的应用
🌐 Resubmit your app
由于你已将更新提供者从 CodePush 更改为 EAS Update,你需要重新构建应用并将新构建提交到相应的应用商店(Google Play 商店和 Apple 应用商店),以确保更新机制能如预期般为终端用户正常工作。
🌐 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.
常见问题
🌐 Common questions
我该如何使用 EAS Update 发布强制/关键更新?
CodePush CLI 有一个 --mandatory 标志,允许你发布强制更新。你可以使用 EAS Update 构建此功能,但没有专门的标志来实现它。
🌐 CodePush CLI has a --mandatory flag that allows you to release mandatory updates. You can build this functionality with EAS Update but there is no specific flag for it.
我如何在更新中添加消息?
CodePush CLI 有一个 --description 标志,允许你在更新中包含消息。你可以在应用配置中使用 extra 字段,通过 EAS Update 构建此功能。
🌐 CodePush CLI has a --description flag that allows you to include a message in an update. You can build this functionality with EAS Update using the extra field in your app config.
在此示例中参考 --message 标志: expo/UpdatesAPIDemo。
🌐 Refer the --message flag in this example: expo/UpdatesAPIDemo.
我如何在运行时切换正在使用的“部署”,类似于 CodePush 中的 sync() 函数?
可以使用 Updates.setUpdateURLAndRequestHeadersOverride() 实现。请在运行时覆盖更新配置指南中了解更多信息。
🌐 This is possible using Updates.setUpdateURLAndRequestHeadersOverride(). Learn more in the Override update configuration at runtime guide.
我如何使用 EAS Update 处理不同的环境(例如预发布环境和生产环境)?
通过 EAS 更新,你可以使用渠道和分支来管理不同的环境和发布。了解更多。
🌐 With EAS Update, you can use channels and branches to manage different environments and rollouts. Learn more.
我如何使用 EAS Update 回滚更新?
你可以使用 eas update:rollback 回滚更新。请在回滚到以前的更新指南中了解更多信息。
🌐 You can roll back updates using eas update:rollback. Learn more in the Rollback to a previous update guide.
我如何使用 EAS 更新逐步推出更新?
EAS 更新支持多种渐进式发布更新的策略,因此你可以选择最适合你需求的方法。了解更多。
🌐 EAS Update supports various strategies for gradually rolling out updates, so you can pick which approach best fits your needs. Learn more.
我如何才能直接控制何时下载和应用更新?
在下载更新指南中了解更多关于下载和应用更新的不同策略,例如在应用运行时或即使在后台时使用 Updates.checkForUpdateAsync() 检查更新。
🌐 Learn more about different strategies for downloading and applying updates in the Downloading updates guide, such as checking for updates while the app is running or even when backgrounded with Updates.checkForUpdateAsync().
EAS 更新支持端到端代码签名吗?
是的,EAS 更新支持端到端代码签名。该功能适用于 EAS 生产版和企业版计划的订阅者。更多信息请参阅代码签名指南。
🌐 Yes, EAS Update supports end-to-end code signing. It is available for EAS Production and Enterprise plan subscribers. Learn more in the Code signing guide.
我还应该了解些什么?
- Expo Orbit:适用于 macOS、Windows 和 Linux 的桌面启动器应用。你可以通过它一键从网站启动更新,还具有其他功能。
- 你可以在 EAS 网站上监控更新的采用情况。了解更多。你还可以从网站上发布和回滚更新。
- 你可以使用 EAS 更新来实现类似网页的预览工作流程。了解更多。
- 使用 EAS 创建的每个更新和构建都关联有一个 指纹。你可以通过网站界面或使用
eas fingerprint:compare对这些指纹进行对比,以查看你的应用在不同构建和更新之间原生运行时发生了哪些变化,从而了解构建/更新的兼容性,并指导你决定何时提升runtimeVersion。
CodePush 和 EAS Update 之间的概念差异
🌐 Conceptual differences between CodePush and EAS Update
CodePush 和 EAS Update 都是允许你向应用的 JavaScript 代码发送热修复的服务,但它们采用的方式略有不同,因此在迁移到 EAS Update 时,你可能需要调整发布流程。
🌐 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.
流中更新组织方式的差异
CodePush 对每个部署有单一的更新流。这意味着你可以将一个构建指向某个部署,它就会从该部署拉取更新。如果你想更改构建所指向的部署,可以通过 JavaScript API 在运行时进行操作。
EAS 更新有多条更新流 —— 一条对应你的源代码控制分支(称为 branches),另一条称为 channels,指向分支。channels 与 branches 之间的映射由服务器端处理,并且一个 channel 可以针对每个运行时版本指向不同的分支(此外,还可以表达更高级的逻辑,例如支持增量发布)。构建并不直接关联到分支,而是关联到 channels。每个构建指向一个单独的 channel,这个 channel 在构建时设置,运行时无法修改。这样做的原因是可以确保某些分支(例如:开发、预发布)不会自动发布到生产环境 —— 你的预览更新不会影响生产用户。这有助于你区分 EAS 更新的两大主要用途:预览和生产热修复。
运行时更新选择方式的差异
CodePush 和 EAS Update 之间对发布流程有影响的一个关键区别是,在 CodePush 中,客户端在运行时控制目标更新的部署,而 在 EAS Update 中,则由服务器端控制,通过将通道映射到分支。这意味着,你不能在使用 EAS Update 的应用中包含代码来根据运行时的条件(例如当前用户角色)加载不同的更新流(例如:将测试版发布给员工)——应用只能加载在 EAS Update 服务器上映射到相应通道(如生产或预发布)的分支。
🌐 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 (for example: 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 Update 的替代方法是使用 开发构建。我们目前正在努力提供一种方法,以便在发布构建中实现这一功能。
🌐 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.