首页指南参考教程

开始使用

了解如何开始在项目中配置和使用 EAS Update 所需的设置。


通过设置 EAS 更新,你可以立即推送用户需要的关键错误修复和改进。本指南将引导你完成在项目中设置 EAS 更新的过程。

¥Setting up EAS Update allows you to push critical bug fixes and improvements that your users need right away. This guide will walk you through the process of setting up EAS Update in your project.

1

安装最新的 EAS CLI

¥Install the latest EAS CLI

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

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

Terminal
npm install --global 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.

2

登录你的 Expo 账户

¥Login 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.

3

创建项目

¥Create a project

通过运行以下命令创建项目:

¥Create a project by running:

Terminal
npx create-expo-app

4

配置你的项目

¥Configure your project

要配置你的项目,请按指定顺序运行以下命令:

¥To configure your project, run the following commands in the order they are specified:

Terminal
# Install the latest `expo-updates` library
npx expo install expo-updates

# Initialize your project with EAS Update
eas update:configure

# Set up the configuration file for builds
eas build:configure

运行这些命令后,将在项目的根目录中创建 eas.json 文件。

¥After running these commands, eas.json file will be created in the root directory of your project.

在 eas.json 的 previewproduction 构建配置文件中,为每个配置文件添加 channel 属性:

¥Inside the preview and production build profiles in eas.json, add a channel property for each:

eas.json
{
  "build": {
    "preview": {
      "channel": "preview"
      // ...
    },
    "production": {
      "channel": "production"
      // ...
    }
  }
}

channel 允许你将该配置文件的版本指向更新。例如,如果我们设置一个 GitHub Action 来发布合并更改,那么我们就可以将代码合并到 "production" Git 分支中。然后,每次提交都会触发一个 GitHub 操作,该操作将发布一个更新,该更新可用于通过通道 "production" 进行构建。

¥The channel allows you to point updates at builds of that profile. For example, if we set up a GitHub Action to publish changes on merge, it will make it so that we can merge code into the "production" Git branch. Then, each commit will trigger a GitHub Action that will publish an update which will be available to builds with the channel "production".

可选的:如果你的项目是一个裸的 React Native 项目,请参阅 裸 React Native 更新指南 了解所需的任何其他配置。

¥Optional: If your project is a bare React Native project, see the bare React Native updates guide for any additional configuration needed.

5

为项目创建一个构建

¥Create a build for the project

你需要创建适用于 Android 或 iOS 的版本。我们建议首先使用 preview 构建配置文件创建构建。请参阅 创建你的第一个版本,了解如何开始使用并为你的设备或模拟器设置 内部分发

¥You need to create a build for Android or iOS. We recommend creating a build with the preview build profile first. See Create your first build on how to get started and set up Internal distribution for your device or simulator.

一旦你的设备或模拟器上运行了构建版本,你就可以发送更新了。

¥Once you have a build running on your device or a simulator, you are ready to send an update.

6

在本地进行更改

¥Make changes locally

创建构建后,你就可以迭代项目了。使用以下命令启动本地开发服务器:

¥After creating the build, you are ready to iterate on the project. Start a local development server with the following command:

Terminal
npx expo start

然后,对项目的 JavaScript、样式或图片资源进行所需的更改。

¥Then, make any desired changes to your project's JavaScript, styling, or image assets.

下一步

¥Next step

发布更新

了解如何使用 EAS Update 将更新发布到特定分支。

Expo 中文网 - 粤ICP备13048890号