首页指南参考教程

从 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.

先决条件

¥Prerequisites

An Expo user account

EAS Update 可供任何拥有 Expo 账户的人使用,无论你是为 EAS 付费还是使用我们的免费计划。你可以在 expo.dev/signup 报名。

¥EAS Update is available to anyone with an Expo account, regardless of whether you pay for EAS or use our Free plan. You can sign up at expo.dev/signup.

了解有关不同计划和福利的更多信息

¥Learn more about different plans and benefits.

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:

Terminal
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

确保正确的 app.json

¥Ensure proper app.json

确保你的项目有一个带有 expo 对象的 app.json 文件。如果你还没有在 app.json 文件中配置任何特定内容,则可以简单地创建一个带有空 expo 对象的最小 app.json 文件,如下所示:

¥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 simply create a minimal app.json file with an empty expo object like this:

app.json
{
  "expo": {
    //... any other existing keys you have
  }
}

3

安装 expo

¥Install the expo package

通过运行以下命令安装 expo 软件包:

¥Install the expo package by running the command:

Terminal
npx install-expo-modules@latest

如果命令失败,请参阅 "安装 Expo 模块" 指南

¥If the command fails, refer to the "Installing Expo modules" guide.

4

安装最新的 EAS CLI

¥Install the latest EAS CLI

EAS CLI 是命令行应用,你将使用它从终端与 EAS 服务进行交互。要安装它,请运行命令:

¥EAS CLI is the command-line app that you will use to interact with EAS services from your terminal. To install it, run the command:

Terminal
npm install -g eas-cli

你还可以使用上述命令检查是否有新版本的 EAS CLI 可用。我们鼓励你始终保持最新版本。

¥You can also use the above command to check if a new version of EAS CLI is available. We encourage you to always stay up to date with the latest version.

我们建议使用 npm 而不是 yarn 进行全局包安装。你也可以使用 npx eas-cli@latest。请记住,只要文档中需要它,就使用它而不是 eas

¥We recommend using npm instead of yarn for global package installations. You may alternatively use npx eas-cli@latest. Remember to use that instead of eas whenever it's called for in the documentation.

5

登录你的 Expo 账户

¥Log in to your Expo account

如果你已使用 Expo CLI 登录 Expo 账户,则可以跳过本节中描述的步骤。如果没有,请运行以下命令登录:

¥If you are already signed in to an Expo account using Expo CLI, you can skip the steps described in this section. If you are not, run the following command to log in:

Terminal
eas login

你可以通过运行 eas whoami 来检查你是否已登录。

¥You can check whether you are logged in by running eas whoami.

6

配置项目、部署构建并发布更新

¥Configure project, deploy builds and publish updates

我们已经完成了为支持 CodePush 的裸 React Native 项目量身定制的所有步骤。要继续配置你的项目,请从 主要指南 中的步骤 4 开始,并按照步骤完成。

¥We have finished all the steps tailored for a CodePush-enabled bare React Native project. To proceed with the configuration of your project, please begin with Step 4 in the main guide and follow it through to completion.

你可能需要编辑 eas update:configure 生成的一些代码,具体取决于你构建和运行项目的方式。有关原生更改的更多详细信息,请参阅 更新裸应用

¥You may need to edit some of the code eas update:configure generates depending on how you build and run your project. See Updating bare app for more details about the native changes.

7

验证迁移并重新提交你的应用

¥Verifying the migration and resubmitting your app

完成迁移并使用 EAS 更新设置项目后,你应该测试你的应用以确保无线更新正常工作。去做这个:

¥After completing the migration and setting up your project with EAS Update, you should test your app to ensure that over-the-air updates are working correctly. To do this:

  1. 在设备或模拟器上安装当前发布的应用版本。

    ¥Install the currently published version of your app on a device or simulator.

  2. 使用 EAS 更新将新更新部署到你的应用。

    ¥Deploy a new update to your app using EAS Update.

  3. 启动应用并确保它从 EAS 加载最新更新。构建更新并将其上传到 EAS 并且命令完成后,强制关闭并重新打开你的应用最多两次以下载和查看更新。

    ¥Launch the app and ensure that it loads the latest update from EAS. Once the update is built and uploaded to EAS and the command completes, force close and reopen your app up to two times to download and view the update.

请记住,由于你已将更新提供程序从 CodePush 更改为 EAS Update,因此你需要重建应用并将新版本提交到相应的应用商店(Apple App Store 和 Google Play Store),以确保更新机制正常工作 你的终端用户的预期。

¥Keep in mind that 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 (Apple App Store and Google Play Store) to ensure the update mechanism works as expected for your end-users.

请遵循相应的商店指南来提交新版本的应用:

¥Please follow the respective store guidelines for submitting a new build of your application:

  • 提交至 Apple App Store

    ¥Submitting to Apple App Store

  • 提交至 Google Play 商店

    ¥Submitting to Google Play Store

成功提交应用后,用户将能够下载并使用集成 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.

Expo 中文网 - 粤ICP备13048890号