iOS 构建过程
了解如何在 EAS Build 上构建 iOS 项目。
本页面介绍了使用 EAS Build 构建 iOS 项目的过程。如果你对构建服务的实现细节感兴趣,可能会想阅读此内容。
🌐 This page describes the process of building iOS projects with EAS Build. You may want to read this if you are interested in the implementation details of the build service.
构建过程
🌐 Build process
让我们更详细地看看使用 EAS Build 构建 iOS 项目的步骤。我们将首先在本地机器上运行一些步骤来准备项目,然后在远程服务上构建项目。
🌐 Let's take a closer look at the steps for building iOS projects with EAS Build. We'll first run some steps on your local machine to prepare the project, and then we'll build the project on a remote service.
本地步骤
🌐 Local steps
第一阶段发生在你的电脑上。EAS CLI 负责完成以下步骤:
🌐 The first phase happens on your computer. EAS CLI is in charge of completing the following steps:
- 如果在 eas.json 中将
cli.requireCommit设置为true,请检查 git 索引是否干净——这意味着没有未提交的更改。如果不干净,EAS CLI 会提供一个选项,让你提交本地更改或中止构建过程。 - 准备构建所需的凭据。
- 根据
builds.ios.PROFILE_NAME.credentialsSource的值,凭证将从本地 credentials.json 文件或 EAS 服务器获取。如果选择了remote模式但尚不存在凭证,将会提示你生成凭证。
- 根据
- Bare 项目需要额外的步骤:检查 Xcode 项目是否配置为可以在 EAS 服务器上构建(以确保设置了正确的 bundle identifier 和 Apple Team ID)。
- 创建包含仓库副本的 tar 包。实际行为取决于你使用的 VCS 工作流程。
- 将项目 tarball 上传到私有 AWS S3 存储桶并将构建请求发送到 EAS Build。
远程步骤
🌐 Remote steps
在下一阶段,当 EAS Build 收到你的请求时,会发生以下情况:
🌐 In this next phase, this is what happens when EAS Build picks up your request:
- 为构建创建一个新的 macOS VM。
- 每个构建都有自己的全新 macOS VM,其中安装了所有构建工具(Xcode、Fastlane 等)。
- 从私有 AWS S3 存储桶下载项目 tarball 并解压。
- 如果设置了
NPM_TOKEN,请创建 .npmrc 。 - 如果在 package.json 中定义了,运行
eas-build-pre-install脚本。 - 在项目根目录下运行
npm install(如果存在 yarn.lock 则运行yarn install)。 - 运行
npx expo-doctor来诊断项目配置中的潜在问题。 - 恢复凭据
- 创建一个新的密钥串。
- 将分发证书导入密钥串。
- 将配置描述文件写入 ~/Library/MobileDevice/Provisioning Profiles 目录。
- 验证分发证书和配置文件是否匹配(每个配置文件都分配给特定的分发证书,并且不能用于使用任何其他证书构建 iOS)。
- 托管项目的额外步骤:运行
npx expo prebuild将项目转换为裸项目。此步骤将使用有版本控制的 Expo CLI。 - 恢复在构建配置中由
cache.key值标识的先前保存的缓存。 - 在项目的 ios 目录下运行
pod install。 - 如果在 package.json 中定义了,运行
eas-build-post-install脚本。 - 使用配置文件的 ID 更新 Xcode 项目。
- 如果 ios 目录中尚不存在 Gymfile,请创建它(请参阅 默认 Gymfile 部分)。
- 在 ios 目录中运行
fastlane gym。 - 已弃用: 如果在 package.json 中定义了,运行
eas-build-pre-upload-artifacts脚本。 - 存储在 build profile 中定义的文件和目录缓存。Podfile.lock 默认会被缓存。后续构建将会恢复此缓存。
- 将应用存档上传到私有 AWS S3 存储桶。
- 可以在 eas.json 的
builds.ios.PROFILE_NAME.applicationArchivePath中配置工件路径。默认路径是 ios/build/App.ipa。你可以为applicationArchivePath指定类似 glob 的模式。我们使用 glob 模式 进行模式匹配。
- 可以在 eas.json 的
- 如果构建成功:如果在 package.json 中定义了,请运行
eas-build-on-success脚本。 - 如果构建失败:请运行 package.json 中定义的
eas-build-on-error脚本(如果有的话)。 - 如果在 package.json 中定义了,请运行
eas-build-on-complete脚本。EAS_BUILD_STATUS环境变量被设置为finished或errored。 - 如果在构建配置中指定了
buildArtifactPaths,请将构建产物归档上传到私有的 AWS S3 存储桶。
使用 Fastlane 构建 iOS 项目
🌐 Building iOS projects with Fastlane
我们正在使用 Fastlane 构建 iOS 项目。更准确地说,我们使用 fastlane gym 命令(查看 Fastlane 文档以了解更多)。此命令允许你在 Gymfile 中声明构建配置。
🌐 We're using Fastlane for building iOS projects. To be more precise, we're using the fastlane gym command (see the Fastlane docs to learn more). This command allows you to declare the build configuration in Gymfile.
EAS Build 可以使用你自己的 Gymfile。你只需要将此文件放在 ios 目录下即可。
🌐 EAS Build can use your own Gymfile. All you need to do is to place this file in the ios directory.
默认健身房文件
🌐 Default Gymfile
如果 ios/Gymfile 文件不存在,iOS 构建工具将创建一个默认文件,其内容大致如下:
🌐 If the ios/Gymfile file doesn't exist, the iOS builder creates a default one which looks similar to the following:
suppress_xcode_output(true) clean(true) scheme("app") export_options({ method: "app-store", provisioningProfiles: { "com.expo.eas.builds.test.application" => "dd83ed9c-4f89-462e-b901-60ae7fe6d737" } }) export_xcargs "OTHER_CODE_SIGN_FLAGS=\"--keychain /tmp/path/to/keychain\"" disable_xcpretty(true) output_directory("./build") output_name("App")