为 iOS 模拟器创建并运行云构建

了解如何使用 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.

观看:为 iOS 模拟器创建开发构建
观看:为 iOS 模拟器创建开发构建

在 eas.json 中创建模拟器构建配置文件

🌐 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:

eas.json
{ "build": { "development": { %%placeholder-start%%... %%placeholder-end%% }, "ios-simulator": { "ios": { "simulator": true } } } }

对于开发版本,必须在配置文件中定义 developmentClientdistribution 属性。为了避免冗余,我们可以扩展 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:

eas.json
{ "ios-simulator": { "extends": "development", "ios": { "simulator": true } } }

iOS 模拟器的开发构建

🌐 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:

Terminal
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 打包标识符是什么?回车 以选择此提示提供的默认值。这将在 app.json 中添加 ios.bundleIdentifier
  • iOS 应用仅使用标准/豁免加密?Y 选择此提示提供的默认值。由于我们的应用不使用加密,它会在 Info.plist 文件中将 ITSAppUsesNonExemptEncryption 设置为 NO,并在你将应用发布到 TestFlight/Apple App Store 时处理相应的合规检查。当你发布自己的应用且使用了加密时,可以选择 N 来跳过下次出现的此提示。

在响应提示后,我们的 EAS 构建会被排队,EAS CLI 会提供一个链接,用于查看构建详情并在 EAS 仪表板上跟踪进度:

🌐 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 EAS 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 应用包标识符是什么?

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

替代:使用 Expo Orbit

你可以使用 Expo Orbit 来安装开发版本。在 EAS 仪表板的 Build artifact 中,点击 用 Expo Orbit 打开,即可在 iOS 模拟器上安装开发版本。

🌐 You can use Expo Orbit to install the development build. From Build artifact on the EAS dashboard, click Open with Expo Orbit to install the development build on the iOS Simulator.

3

运行

🌐 Run

在项目目录下运行 npx expo start 命令来启动开发服务器:

🌐 Start the development server by running the npx expo start command from the project directory:

Terminal
npx expo start

在终端窗口中按 i 以在 iOS 模拟器上打开项目。

概括

🌐 Summary

Chapter 3: Create and run a cloud build for iOS Simulator

我们成功地使用 EAS Build 在 iOS 模拟器上创建并运行了开发版本。

在下一章中,让我们为 iOS 创建一个开发版本,将其安装到设备上,并让它运行起来。

Next: 为 iOS 设备创建并运行云构建