首页指南参考教程

创建开发版本

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


如果你希望在本地创建开发版本,而不是在 EAS 上远程创建,你可以使用 使用 npx expo run:[android|ios] 创建本地版本 或使用 eas build --local

¥If you are looking to create a development build locally, rather than remotely on EAS, you can create local builds with npx expo run:[android|ios] or with eas build --local.

如果你安装了 Android Studio 和 Xcode,则可以使用 EAS 构建在你的本地计算机上 创建开发版本。

¥Development builds can be created with EAS Build or locally on your computer if you have Android Studio and Xcode installed.

在本指南中,你将找到有关使用 EAS 创建开发版本并将其安装在模拟器/模拟器或物理设备上以继续开发应用的信息。

¥In this guide, you'll find information on creating a development build with EAS and installing it on an emulator/simulator or a physical device to continue developing your app.

先决条件

¥Prerequisites

你将需要一个配置为使用 EAS Build 进行构建的 React Native Android 和/或 iOS 项目。如果你尚未配置项目,请参阅 创建你的第一个版本

¥You will need a React Native Android and/or iOS project that is configured to build with EAS Build. If you haven't configured your project yet, see Create your first build.

指示

¥Instructions

以下说明涵盖 Android 和 iOS 以及物理设备和模拟器。你可以使用与你的项目相关的任何说明。如果你更喜欢视频而不是文本,请跳至 视频演练

¥The following instructions cover both Android and iOS and physical devices and emulators. You can use whichever instructions are relevant to your project. If you would prefer a video over text, skip to Video walkthroughs.

1

安装 expo-dev-client

¥Install expo-dev-client

Terminal
npx expo install expo-dev-client
Are you using this library in a bare React Native app?

不使用 持续的原生生成 的应用需要遵循 在裸 React Native 中安装 expo-dev-client 中的说明。

¥Apps that don't use Continuous Native Generation need to follow instructions from Install expo-dev-client in bare React Native.

2

验证你的 eas.json 配置

¥Verify your eas.json configuration

第一次运行 eas build 命令时,它会在项目目录的根目录下创建一个 eas.json 文件。eas.json 包含三个默认构建配置文件 - developmentpreviewproduction。如果你自首次初始化 eas.json 以来已删除 development 配置文件,则应立即将其添加回来。最小配置如下所示:

¥The first time you run the eas build command, it creates an eas.json file at the root of your project directory. The eas.json includes three default build profiles — development, preview, and production. If you have removed the development profile since you first initialized eas.json, you should add it back now. A minimal configuration is shown below:

eas.json
{
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "preview": {
      "distribution": "internal"
    },
    "production": {}
  }
}

development 配置文件设置以下选项:

¥The development profile sets the following options:

  • developmentClienttrue 创建调试版本。它还会生成一个构建工件,你可以将其安装在 Android 设备或模拟器上,或者使用 内部分配 的 iOS 设备上。

    ¥developmentClient to true to create a Debug build. It also generates a build artifact you can install on an Android device or emulator, or an iOS device with internal distribution.

  • 为 iOS 设备构建需要 Apple 开发者计划成员资格。如果你没有,则只能针对 iOS 模拟器进行构建。请参阅下一步以获取更多信息。

    ¥Building for an iOS device requires an Apple Developer Program membership. If you don't have one, you can only build for an iOS Simulator. See the next step for more information.

在构建配置文件中 developmentClient 设置为 true 的 iOS 构建应始终作为 internal 分发。如果你要为 TestFlight 进行分发,则必须将分发设置为 store

¥iOS builds where developmentClient is set to true on the build profile should always be distributed as internal. If you are distributing for TestFlight, you have to set the distribution to store.

3

为模拟器/模拟器创建构建

¥Create a build for emulator/simulator

按照以下步骤在 Android 模拟器或 iOS 模拟器上创建并安装开发版本。

¥Follow the steps below to create and install the development build on an Android Emulator or an iOS Simulator.

仅当你想在模拟器/模拟器上开发项目时才需要这样做。否则,如果你使用的是设备,请跳过这些步骤。

¥This is only required if you want to develop a project on an emulator/simulator. Otherwise, skip these steps if you are using a device.

每个平台都有你必须遵循的特定说明:

¥Each platform has specific instructions you'll have to follow:

要在 Android 模拟器上创建并安装开发版本,你需要一个 .apk。要创建它,请运行以下命令:

¥To create and install the development build on an Android Emulator, you will need a .apk. To create it, run the following command:

Terminal
eas build --profile development --platform android

构建完成后,CLI 将提示你自动下载并安装到 Android 模拟器上。出现提示时,按 Y 直接安装到模拟器上。

¥After the build is complete, the CLI will prompt you to automatically download and install it on the Android Emulator. When prompted, press Y to directly install it on the emulator.

请参阅 为 Android 模拟器和设备构建 APK 了解更多信息。

¥See Build APKs for Android Emulators and devices for more information.

要在 iOS 模拟器上创建并安装开发版本,我们建议你为模拟器创建单独的 建立档案,然后在 eas.json 中将 ios.simulator 选项设置为 true

¥To create and install a development build on an iOS Simulator, we recommend you create a separate build profile for the simulator and then set the ios.simulator option to true in the eas.json.

例如,下面的 development-simulator 配置文件仅用于创建 iOS Simulator 的开发版本:

¥For example, the development-simulator profile below is only for creating a development build for iOS Simulator:

eas.json
{
  "build": {
    "development-simulator": {
      "developmentClient": true,
      "distribution": "internal",
      "ios": {
        "simulator": true
      }
    }
  }
}

然后,运行以下命令在 iOS 模拟器上创建开发版本:

¥Then, run the following command to create the development build on an iOS Simulator:

Terminal
eas build --profile development-simulator --platform ios

构建完成后,CLI 将提示你自动下载并安装到 iOS 模拟器上。出现提示时,按 Y 直接安装到模拟器上。

¥After the build is complete, the CLI will prompt you to automatically download and install it on the iOS Simulator. When prompted, press Y to directly install it on the simulator.

请参阅 在模拟器上安装构建 了解更多信息。

¥See Installing build on the simulator for more information.

4

为设备创建构建

¥Create a build for the device

请按照以下步骤在 Android 或 iOS 设备上创建并安装开发版本。每个平台都有你必须遵循的特定说明:

¥Follow the steps below to create and install the development build on an Android or an iOS device. Each platform has specific instructions you'll have to follow:

如果你已为 Android 模拟器创建了开发版本,则无需为设备单独创建。你可以跳过此步骤,因为相同的 .apk 在这两种情况下都适用。

¥If you have created a development build for Android Emulator, you do not need to create it separately for the device. You can skip this step since the same .apk will work in both scenarios.

要在 Android 设备上创建并安装开发版本,你需要一个 .apk。要创建它,请运行以下命令:

¥To create and install the development build on an Android device, you will need a .apk. To create it, run the following command:

Terminal
eas build --profile development --platform android

构建完成后,将构建详细信息页面或 eas build 完成时提供的链接中的 URL 复制到 .apk。然后,将该 URL 发送到你的设备并在你的设备上打开它以下载并安装 .apk。

¥After the build is complete, copy the URL to the .apk from the build details page or the link provided when eas build has finished. Then, send that URL to your device and open it on your device to download and install the .apk.

在 iOS 设备上创建和安装开发版本需要 Apple 开发者成员资格。

要将你想要在 临时配置文件 上开发的任何 iOS 设备注册,请运行以下命令:

¥To register any iOS device you'd like to develop onto your ad hoc provisioning profile, run the following command:

Terminal
eas device:create

注册你的 iOS 设备后,你可以通过运行以下命令来创建开发版本:

¥After registering your iOS device, you can create the development build by running the command:

Terminal
eas build --profile development --platform ios

运行 iOS 16 及更高版本的设备需要启用特殊的操作系统级开发者模式才能安装开发版本。如果你未启用此设置或正在设备上安装你的第一个开发版本,请参阅 iOS 开发者模式 来启用它。

¥Devices running iOS 16 and above require enabling a special OS-level Developer Mode to install development builds. If you don't have this setting enabled or are installing your first development build on your device, see iOS Developer Mode to enable it.

构建完成后,你可以通过 Expo CLI 扫描设备摄像头的二维码将其下载到 iOS 设备上。eas build 命令运行完成后会提供 QR 码。

¥After the build is complete, you can download it on your iOS device by scanning the QR code from the device's camera from the Expo CLI. The QR code is provided when the eas build command has finished running.

你还可以在 Expo 仪表板 的构建页面上找到此二维码。单击“安装”按钮并使用系统摄像头扫描二维码。

¥You can also find this QR code on the build page in the Expo dashboard. Click the Install button and scan the QR code using the system's camera.

视频演练

¥Video walkthroughs

"Build and Deploy React Native Apps with Expo EAS"

Egghead.io 上的课程涵盖了本页的所有信息以及更多信息。

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

观看由开发者成功工程师 Keith Kurak 主持的视频教程,了解如何使用 EAS Build 进行开发构建。

Expo 中文网 - 粤ICP备13048890号