在 EAS 上创建开发版本

了解如何为项目创建开发版本。


当你使用 npx create-expo-app 创建一个新的 Expo 应用时,你从一个项目开始,在本地机器上更新 JavaScript 代码,并在 Expo Go 应用中查看更改。开发构建 本质上是 你自己的 Expo Go 版本,你可以自由使用任何原生库并更改任何原生配置。在本指南中,你将学习如何将运行在 Expo Go 上的项目转换为开发构建,这将使你应用的原生部分完全可定制。

🌐 When you create a new Expo app with npx create-expo-app, you start off with a project where you update the JavaScript code on your local machine and view the changes in the Expo Go app. A development build is essentially your own version of Expo Go where you are free to use any native libraries and change any native config. In this guide, you will learn how to convert your project that runs on Expo Go into a development build, which will make the native side of your app fully customizable.

如何创建开发版本
如何创建开发版本

先决条件

🌐 Prerequisites

这些说明假设你已经有一个在 Expo Go 上运行的 Expo 项目。

🌐 The instructions assume you already have an existing Expo project that runs on Expo Go.

构建原生应用的要求取决于你使用的平台、构建的目标平台以及你是在 EAS 上构建还是在本地机器上构建。

🌐 The requirements for building the native app depend on which platform you are using, which platform you are building for, and whether you want to build on EAS or on your local machine.

在 EAS 上构建

这是构建本地应用最简单的方法,因为它不需要你这边的本地构建工具。构建在 EAS 服务器上进行,这使得可以从非 macOS 平台触发 iOS 构建。

🌐 This is the easiest way to build your native app, as it requires no native build tools on your side. The builds happen on the EAS servers, which makes it possible to trigger iOS builds from non-macOS platforms.

安卓iOS 模拟器iPhone 设备
macOS (*)
Windows (*)
Linux (*)

(*)所有在iPhone设备上运行的构建都需要付费的[Apple Developer](https://developer.apple.com)账户进行构建签名。

使用 EAS CLI 本地构建

任何 EAS CLI 命令都可以在你的本地机器上使用 --local 标志构建。这要求你的本地开发环境已经配置了本地构建工具。阅读更多关于本地应用开发的内容。

🌐 Any EAS CLI command can be built on your local machine with the --local flag. This requires your local development environment to be set up with native build tools. Read more about local app development.

AndroidiOS 模拟器iPhone设备
macOS (*)
Windows (**)
Linux

(*)所有在iPhone设备上运行的构建都需要付费的[Apple Developer](https://developer.apple.com)账户进行构建签名。

(**)没有一级支持,但可以通过 WSL 实现。

本地构建,无需 EAS

在本地构建而不使用 EAS 需要在本地 开发环境 中安装原生构建工具。这是唯一一种在没有付费 Apple 开发者账户的情况下在 iPhone 设备上测试 iOS 构建的方法(仅在 macOS 上可行)。阅读更多关于 本地应用编译 的内容,并查看 从 Expo Go 到开发构建 指南。

🌐 To build locally without EAS requires your local development environment to be set up with native build tools. This is the only way to test your iOS build on an iPhone device without a paid Apple Developer Account (only possible on macOS). Read more about local app compilation and see the Expo Go to Development Build guide.

安卓iOS 模拟器iPhone 设备
macOS
Windows
Linux

开始使用

🌐 Get started

有关详细的逐步说明,请参阅我们的 EAS 教程。也可以在 YouTube 上观看 教程系列

🌐 For detailed, step-by-step instructions, see our EAS Tutorial. Available also as a tutorial series on YouTube.

1

安装 expo-dev-client

🌐 Install expo-dev-client

Terminal
npx expo install expo-dev-client
你是否在现有的(裸)React Native 应用中使用这个库?

不使用 Continuous Native Generation 或使用 npx react-native 创建的应用,在安装此库后需要进一步配置。请参阅 在现有 React Native 应用中安装 expo-dev-client 的步骤 1 和 2。

🌐 Apps that don't use Continuous Native Generation or are created with npx react-native, require further configuration after installing this library. See steps 1 and 2 from Install expo-dev-client in an existing React Native app.

2

构建原生应用(Android)

🌐 Build the native app (Android)

Prerequisites

3 requirements

1.

Expo 账户

如果你还没有注册,请注册一个 Expo 账户。

2.

EAS 命令行接口

已安装并登录 EAS CLI

Terminal
npm install -g eas-cli && eas login

3.

安卓模拟器(可选)

如果你想在模拟器上测试你的应用,Android 模拟器 是可选的。

Terminal
eas build --platform android --profile development

阅读更多关于 EAS 上的 Android 构建 的信息。

🌐 Read more about Android builds on EAS.

2

构建本地应用(iOS 模拟器)

🌐 Build the native app (iOS Simulator)

Prerequisites

3 requirements

1.

Expo 账户

如果你还没有帐号,请注册一个 Expo 账户。

2.

EAS 命令行接口

已安装并登录 EAS CLI

Terminal
npm install -g eas-cli && eas login

3.

安装了 iOS 模拟器的 macOS

iOS 模拟器仅在 macOS 上可用。请确保你已安装 iOS 模拟器

eas.json 中编辑 development 配置,并将 simulator 选项设置为 true(如果你还想为该项目创建 iOS 设备构建,则必须为模拟器构建创建一个单独的配置)。

🌐 Edit development profile in eas.json and set the simulator option to true (you have to create a separate profile for simulator builds if you also want to create iOS device builds for this project).

eas.json
{ "build": { "development": { "ios": { "simulator": true } } } }
Terminal
eas build --platform ios --profile development

iOS 模拟器构建只能安装在模拟器上,不能安装在真实设备上。

🌐 iOS Simulator builds can only be installed on simulators and not on real devices.

阅读有关 EAS 上的 iOS 模拟器构建 的更多信息。

🌐 Read more about iOS Simulator builds on EAS.

2

构建本地应用(iOS设备)

🌐 Build the native app (iOS device)

Prerequisites

3 requirements

1.

Expo 账户

如果尚未注册,请注册一个 Expo 账号。

2.

EAS 命令行接口

已安装并登录 EAS CLI

Terminal
npm install -g eas-cli && eas login

3.

苹果开发者账号

拥有付费的 Apple Developer 账号,用于创建 签名凭证,以便应用可以安装在 iOS 设备上。

Terminal
eas build --platform ios --profile development

iOS 设备构建只能安装在 iPhone 设备上,无法安装在 iOS 模拟器上。

🌐 iOS device builds can only be installed on iPhone devices and not on iOS Simulators.

阅读更多关于 iOS 设备在 EAS 上的构建 的信息。

🌐 Read more about iOS device builds on EAS.

3

安装应用

🌐 Install the app

你需要在你的设备、模拟器或模拟器上安装本地应用。

🌐 You'll need to install the native app on your device, emulator, or simulator.

在 EAS 上构建时

🌐 When building on EAS

如果你在 EAS 上创建开发版本,构建完成后,CLI 会提示你安装该应用。你也可以从 expo.dev 仪表板或使用 Expo Orbit 安装之前的构建版本。

🌐 If you create your development build on EAS, the CLI will prompt you to install the app after the build is finished. You can also install previous builds from the expo.dev dashboard or using Expo Orbit.

使用 EAS CLI 本地构建时

🌐 When building locally using EAS CLI

在本地构建时,构建的输出将是一个归档文件。你可以将其拖放到 Android 模拟器或 iOS 模拟器上进行安装,或者使用 Expo Orbit 从本地电脑安装构建版本。

🌐 When building locally the output of the build will be an archive. You may drag and drop this on your Android Emulator/iOS Simulator to install it, or use Expo Orbit to install a build from your local machine.

4

启动打包器

🌐 Start the bundler

第2步中构建的开发客户端是你应用的原生部分(基本上就是你自己的 Expo Go 版本)。要继续开发,你还需要启动 JavaScript 打包器。

🌐 The development client built in step 2 is the native side of your app (basically your own version of Expo Go). To continue developing, you'll also want to start the JavaScript bundler.

根据你如何构建应用,这可能已经在运行,但如果由于任何原因关闭了进程,无需重新构建你的开发客户端。只需使用以下方式重新启动 JavaScript 打包器:

🌐 Depending on how you built the app, this may already be running, but if you close the process for any reason, there is no need to rebuild your development client. Simply restart the JavaScript bundler with:

Terminal
npx expo start

这与你在 Expo Go 中使用的命令相同。它会检测你的项目是否安装了 expo-dev-client,如果安装了,它将默认针对你的开发构建而不是 Expo Go。

🌐 This is the same command you would have used with Expo Go. It detects whether your project has expo-dev-client installed, in which case it will default to targeting your development build instead of Expo Go.

视频演练

🌐 Video walkthroughs

"EAS Tutorial Series"

YouTube上的课程:学习如何使用Expo应用服务加快开发速度。

"Async Office Hours: How to make a development build with EAS Build"

在本视频教程中,开发者成功工程师 Keith Kurak 将教你如何使用 EAS Build 制作开发版本。