本文档于 2022 年 8 月存档,不会收到任何进一步更新。SDK 46 是 Classic Builds 支持的最后一个 SDK,Classic Build 服务将在 2023 年 1 月 4 日之后停止运行所有 SDK 版本。查看 在你自己的基础架构上运行构建 和 从 CI 触发构建。
¥This doc was archived in August 2022 and will not receive any further updates. SDK 46 is the last SDK supported by Classic Builds and the Classic Build service will stop running for all SDK versions after January 4, 2023. Check out Running builds on your own infrastructure and Triggering builds from CI.
注意:构建独立的 iOS 应用需要 macOS。
¥Note: macOS is required to build standalone iOS apps.
本指南介绍了 Expo 的一项高级功能。在大多数情况下,你可以使用 Expo 的构建服务构建独立的 Expo 应用,如 构建独立应用 指南中所述。
¥This guide describes an advanced feature of Expo. In most cases you can build standalone Expo apps using Expo's build services as described in the guide on Building Standalone Apps.
如果你不想依赖我们构建器的稳定性,并且不喜欢在队列中等待获得独立的应用构建,那么你可以自己构建你的 Expo 项目。你唯一需要的是 Turtle CLI。Turtle CLI 是用于构建 Expo 独立应用的命令行接口。你可以在 CI 和私有计算机上使用它。
¥If you prefer to not rely on our builders stability and you don't like waiting in the queue to get your standalone app build then you can build your Expo project on your own. The only thing you need is Turtle CLI. Turtle CLI is a command line interface for building Expo standalone apps. You can use it both on your CI and your private computer.
¥Install Turtle CLI
¥Prerequisites
你需要安装这些东西:
¥You'll need to have these things installed:
bash
Node.js(版本 10 或更高版本) - 下载最新版本的 Node.js。
¥Node.js (version 10 or newer) - download the latest version of Node.js.
¥For Android builds
macOS 或 Linux
¥macOS or Linux
¥For iOS builds
苹果系统
¥macOS
Xcode(版本 11.4 或更高版本) - 确保你至少运行过一次并且同意许可协议。或者,你可以运行 sudo xcodebuild -license
。
¥Xcode (version 11.4 or newer) - make sure you have run it at least once
and you have agreed to the license agreements. Alternatively you can run sudo xcodebuild -license
.
fastlane - 看看如何安装
¥fastlane - see how to install it
¥Turtle CLI
通过运行以下命令安装 Turtle CLI:
¥Install Turtle CLI by running:
$ npm install -g turtle-cli
然后运行 turtle setup:ios
和/或 turtle setup:android
以验证所有内容均已正确安装。此步骤是可选的,并且也在 turtle build:[ios|android]
第一次运行期间执行。请注意,Android 安装命令会下载、安装和配置适当版本的 Android SDK 和 NDK。
¥Then run turtle setup:ios
and/or turtle setup:android
to verify everything
is installed correctly. This step is optional and is also performed during
the first run of turtle build:[ios|android]
. Please note that the Android setup command
downloads, installs, and configures the appropriate versions of the Android SDK
and NDK.
如果你想让第一次构建更快,你可以向安装命令提供 Expo SDK 版本,如下所示:turtle setup:ios --sdk-version 38.0.0
。这告诉 Turtle CLI 为给定的 SDK 版本下载其他与 Expo 相关的依赖。
¥If you would like to make the first build even faster, you can supply the Expo
SDK version to the setup command like so: turtle setup:ios --sdk-version 38.0.0
.
This tells Turtle CLI to download additional Expo-related dependencies for
the given SDK version.
所有与 Expo 相关的依赖都将安装在你的主目录中名为 .turtle
的目录中。如果你需要释放一些磁盘空间,可以安全地删除此目录。
¥All Expo-related dependencies will be installed in a directory named .turtle
within your home directory. This directory may be removed safely if you ever
need to free up some disk space.
¥Publish your project
当你使用 Turtle CLI 构建独立应用时,构建过程将在你的本地计算机上进行。Turtle CLI 使用与我们的服务器上运行的完全相同的代码库(expo build:[ios|android]
命令)。这意味着在使用 Turtle CLI 构建应用之前,你需要将应用发布到 Expo 的服务器或将其托管在你自己的服务器上。无论你希望 Expo 托管你的应用,还是你想自己托管你的应用,你所需要做的就是遵循相应的指南:
¥When you're building standalone apps with Turtle CLI, the build process is happening on your local machine.
Turtle CLI makes use of exactly the same codebase which is running on our servers (expo build:[ios|android]
command).
This means you're required to publish your app to Expo's servers or host it on your own server before building it with Turtle CLI.
Whether you want Expo to host your app, or you'd like to do it yourself, all you need to do is follow the appropriate guide:
¥Start the build
如果你选择将应用发布到 Expo 服务器,你必须拥有 Expo 开发者账户并向 turtle-cli
提供你的凭据。建议的方法是使用你的凭据定义两个名为 EXPO_USERNAME
和 EXPO_PASSWORD
的环境变量,尽管你也可以从命令行将这些值传递给构建命令。我们建议使用环境变量来帮助你的凭据远离终端历史记录或 CI 日志。
¥If you choose to publish your app to Expo servers, you must have an Expo
developer account and supply your credentials to the turtle-cli
.
The recommended approach is to define two environment variables called
EXPO_USERNAME
and EXPO_PASSWORD
with your credentials, though you may also
pass these values to the build command from the command line. We recommend
using the environment variables to help keep your credentials out of your
terminal history or CI logs.
Turtle CLI 使用已发布的应用清单(而不是本地 app.json/app.config.js 文件)作为应用配置(ios.buildNumber
、android.versionCode
等)的真实来源。
¥Turtle CLI is using the published app manifest (and not the local app.json/app.config.js file)
as a source of truth for your app configuration (ios.buildNumber
, android.versionCode
, and so on).
¥Building for Android
在开始构建之前,请准备以下事项:
¥Before starting the build, prepare the following things:
密钥库
¥Keystore
密钥库别名
¥Keystore alias
密钥库密码和密钥密码
¥Keystore password and key password
要了解如何生成这些内容,请首先参阅 构建独立应用 上的指南。
¥To learn how to generate those, see the guide on Building Standalone Apps first.
分别使用密钥库密码和密钥密码的值设置 EXPO_ANDROID_KEYSTORE_PASSWORD
和 EXPO_ANDROID_KEY_PASSWORD
环境变量。
¥Set the EXPO_ANDROID_KEYSTORE_PASSWORD
and EXPO_ANDROID_KEY_PASSWORD
environment variables with the values of the keystore password and key password,
respectively.
然后,启动独立应用构建:
¥Then, start the standalone app build:
$ turtle build:android \\
--keystore-path /path/to/your/keystore.jks \\
--keystore-alias PUT_KEYSTORE_ALIAS_HERE
如果构建成功完成,你将在日志的最后一行找到构建工件的路径。
¥If the build finishes successfully you will find the path to the build artifact in the last line of the logs.
如果你想打印所有可用命令参数的列表,请运行 turtle build:android --help
。
¥If you want to print the list of all available command arguments,
please run turtle build:android --help
.
¥Building for iOS
除非你仅针对 iOS 模拟器进行构建,否则请准备以下内容:
¥Prepare the following unless you're building only for the iOS Simulator:
苹果团队 ID - (10 个字符的字符串,如 "Q2DBWS92CA")
¥Apple Team ID - (a 10-character string like "Q2DBWS92CA")
分发证书.p12 文件(+密码)
¥Distribution Certificate .p12 file (+ password)
配置文件
¥Provisioning Profile
要了解如何生成这些内容,请首先参阅 构建独立应用 上的指南。
¥To learn how to generate those, see the guide on Building Standalone Apps first.
使用分发证书密码的值设置 EXPO_IOS_DIST_P12_PASSWORD
环境变量。
¥Set the EXPO_IOS_DIST_P12_PASSWORD
environment variable with the value of
the Distribution Certificate password.
然后,启动独立应用构建:
¥Then, start the standalone app build:
$ turtle build:ios \\
--team-id YOUR_TEAM_ID \\
--dist-p12-path /path/to/your/dist/cert.p12 \\
--provisioning-profile-path /path/to/your/provisioning/profile.mobileprovision
如果构建成功完成,你将在日志的最后一行找到构建工件的路径。
¥If the build finishes successfully you will find the path to the build artifact in the last line of the logs.
如果你想打印所有可用命令参数的列表,请运行 turtle build:ios --help
。
¥If you want to print the list of all available command arguments,
please run turtle build:ios --help
.
¥CI configuration file examples
请参阅 expo/turtle-cli-example 存储库,了解如何将 Turtle CLI 与流行的 CI 服务(CircleCI 和 Travis·西尔)结合使用的示例。
¥See the expo/turtle-cli-example repository for examples of how to use Turtle CLI with popular CI services (CircleCI and Travis CI).