了解如何使用 EAS Build 配置 Android 设备和模拟器的开发版本。
在本章中,我们将使用 EAS Build 创建一个可以在 Android 上运行的开发版本。
¥In this chapter, we'll create a development build that can run on Android with EAS Build.
在 Android 设备或模拟器上创建和运行构建的过程是相同的,只是开发构建的安装有所不同。
¥The process for creating and running a build on Android devices or emulators is identical, with differences only in the installation of the development build.
¥Create a build for the development profile
对于 Android,开发版本必须位于 .apk 中。虽然默认的 Android 格式是 .aab,非常适合 Google Play 商店分发,但它无法安装在设备或模拟器上。
¥For Android, the development build must be in the .apk. While the default Android format is .aab, which is ideal for Google Play Store distribution, it cannot be installed on devices or emulators.
要创建 .apk:
¥To create a .apk:
在 eas.json 中,确保 build.development
配置文件下的 developmentClient
设置为 true
。
¥In eas.json, make sure that developmentClient
is set to true
under build.development
profile.
然后,运行 eas build
命令,其中 android
作为平台,development
作为构建配置文件:
¥Then, run the eas build
command with android
as the platform and development
as the build profile:
-
eas build --platform android --profile development
提示:下次运行eas build
命令时,还可以使用-p
来指定平台。它是--platform
的缩写。
该命令提示我们以下问题:
¥This command prompts us with the following questions:
你希望你的 Android 应用 ID 是什么?按 return 选择为此提示提供的默认值。这将在 app.json 中添加 android.package
。
¥What would you like your Android application id to be? Press return to select the default value provided for this prompt. This will add android.package
in app.json.
生成新的 Android 密钥库?按 Y。
¥Generate a new Android Keystore? Press Y.
响应后,构建将排队,我们可以通过 Expo 仪表板中 EAS CLI 提供的链接跟踪其进度:
¥After responding, the build will queue up, and we can track its progress via a provided link by the EAS CLI in the Expo dashboard:
构建详细信息页面显示构建类型、配置文件、Expo SDK 版本、应用版本、版本代码、上次提交哈希以及发起构建的开发者或账户所有者的身份。
¥The build details page displays the build type, profile, Expo SDK version, app version, version code, last commit hash, and the identity of the developer or account owner who initiated the build.
在上图中,构建工件的当前状态显示构建正在进行中。完成后,此部分将提供下载构建版本的选项。日志概述了 EAS Build 上的 Android 构建过程中所采取的每个步骤。为了简洁起见,我们不会在这里详细探讨每个步骤。要了解更多信息,请参阅 安卓构建流程。
¥In the above image, the current status of the Build artifact shows that the build is in progress. Upon completion, this section will offer an option to download the build. The Logs outlines every step taken during the Android build process on EAS Build. For the sake of brevity, we won't explore each step in detail here. To learn more, see Android build process.
也称为 Android 应用的包名称,它以 DNS 反向表示法 (com.owner.appname
) 存储值。此表示法的每个组成部分都应以小写字母开头。
¥Also known as the package name of our Android app, it stores the value in DNS reverse notation format (com.owner.appname
). Each component of this notation should start with a lowercase letter.
例如,我们的示例应用有 com.owner.stickersmash
,其中 com.owner
是域,stickersmash
是我们的应用名称。
¥For example, our example app has com.owner.stickersmash
where com.owner
is the domain and stickersmash
is our app name.
¥Android device
1
¥Install development build
构建完成后,构建工件部分将更新,表明构建已完成:
¥Once the build finishes, the Build artifact section gets updated, indicating that the build is complete:
本节提供了可用于在 Android 设备上运行开发版本的方法:Expo 轨道和安装按钮。
¥This section provides the methods available for running the development build on an Android device: Expo Orbit and Install button.
Expo 轨道 允许在 Android 设备上无缝安装开发版本。要使用此方法:
¥Expo Orbit allows for seamless installation of the development build on an Android device. To use this method:
使用 USB 将我们的 Android 设备连接到本地计算机。
¥Connect our Android device to our local machine using USB.
打开 Orbit 菜单栏应用。
¥Open the Orbit menu bar app.
在 Orbit 应用中选择设备。
¥Select the Device in the Orbit app.
在 Expo 仪表板上的“构建工件”下,单击“使用 Orbit 打开”。
¥On the Expo dashboard, under Build artifact, click the Open with Orbit.
安装版本后,Orbit 应用会在设备上启动开发版本。
¥After the build is installed, the Orbit app launches the development build on the device.
2
¥Run development build
通过从项目目录运行 npx expo start
来启动开发服务器。服务器运行后,在终端窗口中按 a 打开项目:
¥Start the development server by running npx expo start
from the project directory. Once the server is running, press a in the terminal window to open the project:
-
npx expo start
¥Android Emulator
1
¥Install the development build
在终端中,构建完成后,EAS CLI 会提示我们询问是否要在 Android 模拟器上运行构建。按 Y。
¥In the terminal, once the build finishes, EAS CLI prompts us by asking whether we want to run the build on an Android Emulator. Press Y.
或者,Expo 轨道 可用于安装。从 Expo 仪表板上的“构建工件”中,单击“使用 Expo Orbit 打开”以在 Android 模拟器上安装开发版本。
¥Alternatively, Expo Orbit can be used for installation. From Build artifact on the Expo dashboard, click Open with Expo Orbit to install the development build on the Android Emulator.
2
¥Run the development build
通过从项目目录运行 npx expo start
来启动开发服务器。服务器运行后,在终端窗口中按 a 打开项目:
¥Start the development server by running npx expo start
from the project directory. Once the server is running, press a in the terminal window to open the project:
-
npx expo start
¥Summary
Chapter 2: Create and run a cloud build for Android
We successfully used EAS Build to create and run development builds on Android devices and emulators, and learned about .apk and .aab file formats.
In the next chapter, learn how to configure a development build for iOS Simulators using EAS Build and get it running.