了解如何使用 EAS Build 配置 iOS 模拟器的开发构建。
在本章中,我们将创建一个可以使用 EAS Build 在 iOS 模拟器上运行的开发版本。
¥In this chapter, we'll create a development build that can run on an iOS Simulator with EAS Build.
iOS 模拟器的开发版本以 .app 格式生成,这与 iOS 设备不同。
¥Development builds for iOS Simulators are generated in the .app format which is different from iOS devices.
¥Create a simulator build profile in eas.json
在 eas.json 中,添加一个名为 ios-simulator
的新构建配置文件,其属性为 ios.simulator
属性。设置其值 true
:
¥In eas.json, add a new build profile called ios-simulator
with the property ios.simulator
property. Set its value true
:
{
"build": {
"development": {
%%placeholder-start%%... %%placeholder-end%%
},
"ios-simulator": {
"ios": {
"simulator": true
}
}
}
}
对于开发版本,必须在配置文件中定义 developmentClient
和 distribution
属性。为了避免冗余,我们可以扩展 development
配置文件属性:
¥For a development build, it's necessary to have the developmentClient
and distribution
properties defined in the profile. To avoid redundancy, we can extend the development
profile properties:
{
"ios-simulator": {
"extends": "development",
"ios": {
"simulator": true
}
}
}
}
¥Development build for iOS Simulator
1
¥Create
使用 ios
作为平台、ios-simulator
作为构建配置文件运行 eas build
命令:
¥Run the eas build
command with ios
as a platform and ios-simulator
as the build profile:
-
eas build --platform ios --profile ios-simulator
当我们第一次创建构建时,该命令会提示我们以下问题:
¥This command prompts us with the following questions when we create the build for the first time:
你希望你的 iOS 包标识符是什么?按 return 选择为此提示提供的默认值。这将在 app.json 中添加 ios.bundleIdentifier
。
¥What would you like your iOS bundle identifier to be? Press return to select the default value provided for this prompt. This will add ios.bundleIdentifier
in app.json.
响应提示后,我们的 EAS 构建已排队,并且 EAS CLI 提供了一个链接,用于在 Expo 仪表板上查看构建详细信息并跟踪进度:
¥After responding to the prompts, our EAS Build is queued, and the EAS CLI provides a link to view build details and track progress on the Expo dashboard:
构建详细信息页面显示构建类型、配置文件、Expo SDK 版本、应用版本、构建号、上次提交哈希以及发起构建的开发者或账户所有者的身份。
¥The build details page displays the build type, profile, Expo SDK version, app version, build number, last commit hash, and the identity of the developer or account owner who initiated the build.
在上图中,构建工件的当前状态显示构建正在进行中。完成后,此部分将提供下载构建版本的选项。日志概述了 EAS Build 上的 iOS 构建过程中采取的每个步骤。为了简洁起见,我们不会在这里详细探讨每个步骤。要了解更多信息,请参阅 iOS 构建过程。
¥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 iOS build process on EAS Build. For the sake of brevity, we won't explore each step in detail here. To learn more, see iOS build process.
ios.bundleIdentifier
是我们应用的唯一名称。如果我们现在发布我们的应用,Apple App Store 将使用此属性及其值来识别商店中的应用。
¥The ios.bundleIdentifier
is a unique name of our app. If we publish our app right now, the Apple App Store will use this property and its value to identify our app on the store.
该符号定义为 host.owner.app-name
。例如,我们的示例应用有 com.owner.stickersmash
,其中 com.owner
是域,stickersmash
是我们的应用名称。
¥This notation is defined as host.owner.app-name
. For example, our example app has com.owner.stickersmash
where com.owner
is the domain and stickersmash
is our app name.
2
¥Install
在终端中,构建完成后,EAS CLI 会提示我们询问是否要在 iOS 模拟器上运行构建。按 Y。
¥In the terminal, once the build finishes, EAS CLI prompts us by asking whether we want to run the build on an iOS Simulator. Press Y.
3
¥Run
通过从项目目录运行 npx expo start
命令来启动开发服务器:
¥Start the development server by running the npx expo start
command from the project directory:
-
npx expo start
在终端窗口中按 i 以在 iOS 模拟器上打开项目。
¥Press i in the terminal window to open the project on the iOS Simulator.
¥Summary
Chapter 3: Create and run a cloud build for iOS Simulator
We successfully used EAS Build to create and run development builds on iOS Simulators.
In the next chapter, let's create a development build for iOS, install it on a device, and get it running.