了解如何在 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 将提供一个选项来为你提交本地更改或中止构建过程。
¥If cli.requireCommit
is set to true
in eas.json, check if the git index is clean - this means that there aren't any uncommitted changes. If it's not clean, EAS CLI will provide an option to commit local changes for you or abort the build process.
准备构建所需的凭据。
¥Prepare the credentials needed for the build.
根据 builds.ios.PROFILE_NAME.credentialsSource
的值,凭证是从本地凭据.json 文件或 EAS 服务器获取的。如果选择了 remote
模式但尚不存在凭据,系统会要求你生成它们。
¥Depending on the value of builds.ios.PROFILE_NAME.credentialsSource
, the credentials are obtained from either the local credentials.json file or from the EAS servers. If the remote
mode is selected but no credentials exist yet, you're offered to generate them.
裸项目需要额外的步骤:检查 Xcode 项目是否配置为可在 EAS 服务器上构建(以确保设置正确的打包包标识符和 Apple 团队 ID)。
¥Bare projects require an additional step: check whether the Xcode project is configured to be buildable on the EAS servers (to ensure the correct bundle identifier and Apple Team ID are set).
创建包含存储库副本的 tarball。实际行为取决于你使用的 视频控制系统工作流程。
¥Create the tarball containing a copy of the repository. Actual behavior depends on the VCS workflow you are using.
将项目 tarball 上传到私有 AWS S3 存储桶并将构建请求发送到 EAS Build。
¥Upload the project tarball to a private AWS S3 bucket and send the build request to EAS Build.
¥Remote steps
在下一阶段,当 EAS Build 收到你的请求时,会发生以下情况:
¥In this next phase, this is what happens when EAS Build picks up your request:
为构建创建一个新的 macOS VM。
¥Create a new macOS VM for the build.
每个构建都有自己的全新 macOS VM,其中安装了所有构建工具(Xcode、Fastlane 等)。
¥Every build gets its own fresh macOS VM with all build tools installed there (Xcode, Fastlane, and so on).
从私有 AWS S3 存储桶下载项目 tarball 并解压。
¥Download the project tarball from a private AWS S3 bucket and unpack it.
如果设置了 NPM_TOKEN
,则为 创建.npmrc。
¥Create .npmrc if NPM_TOKEN
is set.
从 package.json 运行 eas-build-pre-install
脚本(如果已定义)。
¥Run the eas-build-pre-install
script from package.json if defined.
在项目根目录中运行 npm install
(如果 yarn.lock 存在,则运行 yarn install
)。
¥Run npm install
in the project root (or yarn install
if yarn.lock exists).
运行 npx expo-doctor
来诊断项目配置的潜在问题。
¥Run npx expo-doctor
to diagnose potential issues with your project configuration.
恢复凭据
¥Restore the credentials
创建一个新的密钥串。
¥Create a new keychain.
将分发证书导入密钥串。
¥Import the Distribution Certificate into the keychain.
将配置文件写入 ~/Library/MobileDevice/Provisioning Profiles 目录。
¥Write the Provisioning Profile to the ~/Library/MobileDevice/Provisioning Profiles directory.
验证分发证书和配置文件是否匹配(每个配置文件都分配给特定的分发证书,并且不能用于使用任何其他证书构建 iOS)。
¥Verify that the Distribution Certificate and Provisioning Profile match (every Provisioning Profile is assigned to a particular Distribution Certificate and cannot be used for building the iOS with any other certificate).
托管项目的附加步骤:运行 npx expo prebuild
将项目转换为裸项目。此步骤将使用版本化的 Expo CLI。
¥Additional step for managed projects: Run npx expo prebuild
to convert the project to a bare one. This step will use the versioned Expo CLI.
恢复以前保存的由 建立档案 中的 cache.key
值标识的缓存。
¥Restore a previously saved cache identified by the cache.key
value in the build profile.
在项目内的 ios 目录中运行 pod install
。
¥Run pod install
in the ios directory inside your project.
从 package.json 运行 eas-build-post-install
脚本(如果已定义)。
¥Run the eas-build-post-install
script from package.json if defined.
使用配置文件的 ID 更新 Xcode 项目。
¥Update the Xcode project with the ID of the Provisioning Profile.
如果 Gymfile 不存在,请在 ios 目录中创建它(查看 默认健身房文件 部分)。
¥Create Gymfile in the ios directory if it does not already exist (check out the Default Gymfile section).
在 ios 目录下运行 fastlane gym
。
¥Run fastlane gym
in the ios directory.
已弃用:从 package.json 运行 eas-build-pre-upload-artifacts
脚本(如果已定义)。
¥Deprecated: Run the eas-build-pre-upload-artifacts
script from package.json if defined.
存储 建立档案.conf 中定义的文件和目录的缓存。Podfile.lock 默认被缓存。后续构建将恢复此缓存。
¥Store a cache of files and directories defined in the build profile. Podfile.lock is cached by default. Subsequent builds will restore this cache.
将应用存档上传到私有 AWS S3 存储桶。
¥Upload the application archive to a private AWS S3 bucket.
工件路径可以在 builds.ios.PROFILE_NAME.applicationArchivePath
处的 eas.json 中配置。它默认为 ios/build/App.ipa。你可以为 applicationArchivePath
指定类似 glob 的模式。我们在底层使用 fast-glob 包。
¥The artifact path can be configured in eas.json at builds.ios.PROFILE_NAME.applicationArchivePath
. It defaults to ios/build/App.ipa. You can specify a glob-like pattern for applicationArchivePath
. We're using the fast-glob package under the hood.
如果构建成功:如果已定义,则运行 package.json 中的 eas-build-on-success
脚本。
¥If the build was successful: run the eas-build-on-success
script from package.json if defined.
如果构建失败:如果已定义,则运行 package.json 中的 eas-build-on-error
脚本。
¥If the build failed: run the eas-build-on-error
script from package.json if defined.
从 package.json 运行 eas-build-on-complete
脚本(如果已定义)。EAS_BUILD_STATUS
环境变量设置为 finished
或 errored
。
¥Run the eas-build-on-complete
script from package.json if defined. The EAS_BUILD_STATUS
env variable is set to either finished
or errored
.
如果在构建配置文件中指定了 buildArtifactPaths
,则将构建工件存档上传到私有 AWS S3 存储桶。
¥Upload the build artifacts archive to a private AWS S3 bucket if buildArtifactPaths
is specified in the build profile.
¥Building iOS projects with 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")