为 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.

Watch: Creating a development build for iOS Simulator
Watch: Creating a development build for iOS Simulator

在 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

Run the eas build command with ios as a platform and ios-simulator as the build profile:

!!!IG2!!!

This command prompts us with the following questions when we create the build for the first time:

  • 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.

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:

What does a build details page contain?

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.

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.

What is iOS bundle identifier?

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.

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

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.

Alternate: Use Expo Orbit

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

3

Run

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

!!!IG3!!!

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.

Next: Create and run a cloud build for iOS device