本文档于 2022 年 8 月存档,不会收到任何进一步更新。SDK 46 是 Classic Builds 支持的最后一个 SDK,Classic Build 服务将在 2023 年 1 月 4 日之后停止运行所有 SDK 版本。请改用 EAS 构建。
¥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. Instead, use EAS Build.
经典构建服务允许你使用 Expo CLI 为 Expo 应用创建独立的二进制文件。你可以使用该二进制文件将应用提交到 Apple App Store 和 Google Play Store 或在模拟器上进行测试。
¥Classic Build service allows you to create standalone binaries for the Expo app using the Expo CLI. You can use that binary to submit the app to the Apple App Store and Google Play Store or test on emulators.
构建独立的 iOS 应用需要 Apple 开发者账户,但构建独立的 Android 应用不需要 Google Play 开发者账户。要提交到任一应用商店,你需要该商店的开发者账户。
¥An Apple Developer account is required to build a standalone iOS app, but a Google Play Developer account is not required to build the standalone Android app. To submit to either app store, you need a developer account on that store.
我们建议你阅读 关于应用商店的最佳实践 以确保你的应用被 Apple 和 Google 商店接受。一旦你创建了令人惊叹的应用,EAS Build 可以帮助你构建它,然后将其提交到应用商店。
¥We recommend that you read the best practices about app stores to ensure your app gets accepted into the Apple and Google stores. Once you have created an amazing app, EAS Build can help you build it and then submit it to the app stores.
¥ Install Expo CLI
Expo CLI 是构建独立应用所需的命令行应用。它作为全局 npm 包安装。如果你尚未安装,请通过 Expo CLI 文档中的安装步骤。
¥Expo CLI is a command-line application required to build standalone apps. It is installed as a global npm package. If you have not installed it, go through the installation steps in the Expo CLI documentation.
你必须拥有 Expo 账户并登录才能创建构建。运行构建命令时,你可以创建新账户或登录现有账户。
¥You must have an Expo account and be logged in to create a build. When running the build command, you can create a new account or log in to an existing account.
使用 Windows 操作系统的开发者必须启用 WSL。如果你尚未安装,请按照此 安装指南。当提示选择 Linux 发行版时,我们建议从 Windows 应用商店中选择 Ubuntu。至少启动一次 Ubuntu,然后使用管理 PowerShell 运行命令:
¥Developers using the Windows operating system must have WSL enabled. If you do not have it installed, follow this installation guide. When it prompts for choosing a Linux distribution, we recommend picking Ubuntu from the Windows Store. Launch Ubuntu at least once and then use an admin PowerShell to run the command:
-
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
¥ Configure app.json
在 app.json 中,你必须在运行构建命令之前添加一组配置。下面的代码片段代表了配置的最低所需版本:
¥In app.json, you have to add a set of configurations before running the build command. The code snippet below represents a minimal required version of the configuration:
{
"expo": {
"name": "Your App Name",
"icon": "./path/to/your/app-icon.png",
"version": "1.0.0",
"slug": "your-app-slug",
"ios": {
"bundleIdentifier": "com.yourcompany.yourappname",
"buildNumber": "1.0.0"
},
"android": {
"package": "com.yourcompany.yourappname",
"versionCode": 1
}
}
}
以下是配置 app.json 或 app.config.js 文件时必须注意的必填字段:
¥Here are the required fields that you have to pay attention to when configuring your app.json or app.config.js file:
添加 name
、icon
、version
等字段。
¥Add fields such as name
, icon
, and version
.
iOS bundleIdentifier
和 Android package
字段使用反向 DNS 表示法,但不必与域相关。将 "com.yourcompany.yourappname"
替换为对你的应用有意义的任何内容。
¥The iOS bundleIdentifier
and Android package
fields use reverse DNS notation but do not have to be related to a domain. Replace "com.yourcompany.yourappname"
with whatever makes sense for your app.
slug
应该是 URL 安全值。该 slug 将包含在你的应用的 JavaScript 发布到的 URL 中。例如:expo.dev/@community/native-component-list
,其中 community
是用户名,native-component-list
是别名。
¥The slug
should be a URL safe value. The slug will be included in the URL that your app's JavaScript is published to. For example: expo.dev/@community/native-component-list
, where community
is the username and native-component-list
is the slug.
ios.buildNumber
和 android.versionCode
区分应用的不同二进制文件。确保为你上传到 App Store 或 Google Play Store 的每个版本增加这些值。
¥The ios.buildNumber
and android.versionCode
distinguish different binaries of your app. Make sure to increment these for each build you upload to the App Store or Google Play Store.
你还可以将其他选项添加到 app.json 中。例如,一些开发者喜欢配置自己的内部版本号、链接方案等。我们建议你浏览 使用 app.json/app.config.js 进行配置 了解完整规范。在此步骤中,还要检查 应用商店最佳实践。它提供了有关应用商店需要哪些类型的元数据的详细信息。
¥There are other options you can add to app.json. For example, some developers like to configure their own build number, linking scheme, and so on. We recommend you go through Configuration with app.json/app.config.js for the full specification. At this step, also check App stores best practices. It provides details on what types of metadata are required for the app stores.
¥ Start the build
要开始构建过程,请根据你构建的平台运行 expo build:android
或 expo build:ios
。如果你正在构建的应用没有运行开发服务器,expo
将自动启动它。
¥To start the build process, run expo build:android
or expo build:ios
depending on the platform you are building for. If there is no development server running for the app you are building, expo
will start it automatically.
当你运行
expo build
时,Expo 会自动发布你的应用(使用经典更新的expo publish
命令)。为了避免意外发布对生产应用的更改,你可能需要使用 发布渠道。¥When you run
expo build
, Expo automatically publishes your app (with Classic Update'sexpo publish
command). To avoid accidentally publishing changes to your production app, you may want to use release channels.
¥Building for Android
在构建 Android 独立应用时,你可以生成两种类型的构建:APK 或 Android 应用包 (aab)。
¥There are two types of build you can generate when building a standalone app for Android: an APK or an Android App Bundle (aab).
要构建 APK,请运行以下命令:
¥To build an APK, run the command:
-
expo build:android -t apk
我们建议构建一个 Android App Bundle (aab) 以将应用提交到 Google Play 商店。要构建 aab,请运行以下命令:
¥We recommend building an Android App Bundle (aab) for submitting the app to the Google Play Store. To build an aab, run the command:
-
expo build:android -t app-bundle
构建 aab 时,请确保为你的项目启用 Google Play 应用签名。你可以在 安卓文档 中阅读更多相关信息。
¥When building an aab, make sure Google Play App Signing is enabled for your project. You can read more about it in the Android documentation.
¥Generating keystore
第一次构建应用时,你必须生成 keystore。如果你熟悉生成密钥库的过程,你可以上传自己的密钥库,也可以让 Expo 处理该过程。
¥When building your app for the first time, you'll have to generate a keystore. You can upload your own if you are familiar with the process of generating keystores, or you can let Expo handle the process.
为了让 Expo 处理该过程,请在提示输入密钥库时选择命令行中的第一个选项:
¥For Expo to handle the process, choose the first option in the command-line when prompted for keystore:
[exp] No currently active or previous builds for this project.
Would you like to upload a keystore or have us generate one for you?
If you don't know what this means, let us handle it! :)
1) Let Expo handle the process!
2) I want to upload my own keystore!
如果你选择第一个选项,强烈建议你在构建过程完成后运行以下命令。运行后,将密钥库备份到安全位置:
¥If you choose the first option, it is strongly recommended that you run the following command after the build process is complete. After running it, backup the keystore in a safe location:
-
expo fetch:android:keystore
将应用提交到 Google Play 商店后,该应用的所有未来更新都必须使用 Play 商店最初接受的同一密钥库进行签名。如果你没有密钥库的本地副本,你将无法将应用的新版本发布到 Play 商店。
¥Once you submit the app to the Google Play Store, all future updates to that app must be signed with the same keystore that the Play Store initially accepted. If you do not have a local copy of your keystore, you will be unable to publish new versions of your app to the Play Store.
如果出于任何原因你将来删除项目或清除凭据,则在不提供相同密钥库的情况下,你将无法向应用提交任何更新。如果你无法检索梯形校正,你唯一的选择就是生成新的密钥库并将你的应用重新上传为新应用。
¥If for any reason you delete your project or clear your credentials in the future, you will not be able to submit any updates to your app without providing the same keystore. If you're unable to retrieve the keystone, your only option left is to generate a new keystore and re-upload your application as a new application.
¥Uploading your keystore after publishing the app
如果你在生成密钥库时选择第一个选项,然后决定上传自己的密钥库,则可以使用该选项通过运行以下命令从 Expo 的构建服务器中清除当前的 Android 密钥库:
¥If you choose the first option when generating the keystore and later decide to upload your own keystore, you can use the option to clear the current Android keystore from Expo's build servers by running the command:
-
expo build:android --clear-credentials
这是不可逆的,因此仅当你生成了自己的密钥库时才运行此命令。你可以详细了解代码签名和密钥库如何在 安卓文档 中工作。
¥This is irreversible, so only run this command if you have generated your own keystore. You can learn more about how code signing and keystores work in the Android documentation.
¥Building for iOS
在构建 iOS 独立应用时,你可以生成两种类型的构建:存档和模拟器。
¥There are two types of build you can generate when building a standalone app for iOS: archive and simulator.
存档版本用于将应用提交到 Apple App Store 并使用 TestFlight 等功能进行分发。要构建 iOS 应用存档,请运行:
¥Archive builds are used for submitting your app to the Apple App Store and distributing it with features like TestFlight. To build an iOS app archive, run:
-
expo build:ios -t archive
模拟器构建用于在 iOS 模拟器中测试独立应用。要构建一个,请运行:
¥Simulator builds are used to test a standalone app in an iOS Simulator. To build one, run:
-
expo build:ios -t simulator
在针对 iOS 进行构建时,你可以选择让 Expo 创建你的应用所需的任何必要凭据。但是,如果你愿意,你仍然可以选择提供自己的凭据。在此过程中,Expo CLI 将使用你的 Apple ID 和密码。你的身份验证信息仅在你的计算机本地使用,绝不会发送到 Expo 的服务器。
¥When building for iOS, you can choose to let Expo create any necessary credentials that your app will need. However, you'll still have the choice to provide your own credentials if you'd like. During this process, Expo CLI will use your Apple ID and password. Your authentication information is only used locally on your computer and is never sent to Expo's servers.
$ expo build:ios
[16:44:37] Checking if current build exists...
[16:44:37] No currently active or previous builds for this project.
[16:44:37]
We need your Apple ID/password to manage certificates, keys
and provisioning profiles from your Apple Developer account.
Note: Expo does not keep your Apple ID or your Apple ID password.
? What\'s your Apple ID? xxx@yyy.zzz
? Password? [hidden]
✔ Authenticated with Apple Developer Portal successfully!
[16:44:46] You have 4 teams associated with your account
? Which team would you like to use? 3) ABCDEFGHIJ "John Turtle" (Individual)
✔ Ensured App ID exists on Apple Developer Portal!
[16:44:59] We do not have some credentials for you: Apple Distribution Certificate, Apple Push Notifications service key, Apple Provisioning Profile
? How would you like to upload your credentials? (Use arrow keys)
❯ Expo handles all credentials, you can still provide overrides
I will provide all the credentials and files needed, Expo does limited validation
如果你不熟悉 iOS 凭证,建议让 Expo 处理凭证的创建和管理。要了解有关它们的更多信息,请参阅 应用凭证文档。
¥If you are unfamiliar with iOS credentials, it is recommended to let Expo handle the creation and management of credentials. To learn more about them, refer to the App Credentials documentation.
如果你熟悉 iOS 凭据并计划提供自己的凭据,请使用 苹果开发者门户 创建它们。
¥If you are familiar with iOS credentials and plan to provide your own, use the Apple Developer Portal to create them.
¥Enterprise distribution
要使用 Apple 的企业发行版构建和分发你的应用,你需要是 Apple 开发者企业计划 的成员。
¥To build and distribute your app using Apple's Enterprise distribution, it is required that you are a member of the Apple Developer Enterprise Program.
Expo 的构建服务支持企业分发。当你运行 expo build:ios
时,你需要选择标有 (In-House)
的正确团队。
¥Expo's build service supports Enterprise distribution. When you run expo build:ios
, you'll need to choose the correct team that is labeled with (In-House)
.
¥Adhoc distribution
此分发方法要求你覆盖自己的凭据。如果你知道如何生成 iOS 凭证,请使用此发行版。
¥This distribution method requires you to override your own credentials. Use this distribution if you know how to generate iOS credentials.
测试独立应用的最简单方法之一是使用 模拟器构建,然后使用 TestFlight 对物理设备进行测试。但是,如果你想通过 Xcode 直接在物理设备上构建并安装应用,请按照以下步骤使用 Expo CLI 生成应用:
¥One of the easiest ways to test your standalone app is using a simulator build and then using TestFlight for your physical device for testing. However, if you want to build and install an app directly on a physical device through Xcode, follow the steps below to generate one using Expo CLI:
通过运行以下命令生成初步证书,例如应用标识符和分发证书:
¥Generate preliminary certificates such as app identifier and distribution certificate by running the command:
-
expo build:ios
现在,创建一个新的 配置文件,并在 Distribution
下选择 Adhoc
。
¥Now, create a new provisioning profile, and under Distribution
, select Adhoc
.
提供你在第一步中创建的应用标识符和分发证书。如果你不提供这些确切的证书,你的构建将会失败。
¥Provide the app identifier and the distribution certificate you created in the first step. If you don't provide those exact certificates, your build will fail.
下载配置文件,然后将其传递给构建命令:
¥Download the provisioning profile, and then pass it to the build command:
-
expo build:ios --provisioning-profile-path ~/Path/To/provisioningProfileYouCreated.mobileprovision
确保你使用的其他证书与你在上一步中创建临时配置文件时选择的证书相匹配。
¥Make sure the other certificates you use match the ones you selected when creating your adhoc provisioning profile in the previous step.
Expo 完成构建后,你可以通过 Xcode 将其安装到你的设备上。
¥After Expo finishes your build, you can install it onto your device via Xcode.
在 Xcode 中打开 Devices & Simulators
窗口
¥Open the Devices & Simulators
window in Xcode
选择你连接的设备
¥Select your connected device
在 Installed Apps
下,单击加号 (+
),然后选择 Expo 生成的 IPA
¥Under Installed Apps
, click the plus (+
) and then select the IPA generated by Expo
注意:我们为 iOS 启用了位码,因此 iOS 的 .ipa 文件比用户最终可以在 App Store 下载的文件大得多。欲了解更多信息,请参阅 应用细化。
¥Note: We enable bitcode for iOS, so the .ipa files for iOS are much larger than the eventual App Store download available to your users. For more information, see App Thinning.
¥Switch to Push Notification Key on iOS
如果你使用推送通知证书并想要切换到 推送通知键,请使用 --clear-push-cert
选项开始构建。Expo 将从其服务器中删除旧证书并为你生成推送通知密钥。
¥If you use a Push Notifications Certificate and want to switch to a Push Notifications Key, start the build with --clear-push-cert
option. Expo will remove legacy certificates from its servers and generate a Push Notifications Key for you.
¥ Wait for it to finish building
Expo 的构建服务使用云服务来构建你的应用。一旦其中一台机器空闲并准备好使用,构建过程就会开始。要检查构建的等待时间有多长,请访问 海龟状态 站点。
¥Expo's build service uses cloud services to build your app. The build process starts as soon as one of the machines is free and ready to be used. To check how long the waiting time for your build is, visit Turtle status site.
Expo CLI 会打印一个 URL,你可以访问该 URL 并检查构建的进度和日志。
¥Expo CLI prints a URL that you can visit and check your build for its progress and logs.
或者,你可以通过运行以下命令来检查状态:
¥Alternatively, you can check the status by running:
-
expo build:status
构建过程完成后,你将获得应用文件的 URL - .apk、.aab(均为 Android)或 .ipa (iOS) 文件。将链接复制并粘贴到浏览器中以下载文件。
¥When the build process finishes, you will get a URL to your app file - an .apk, .aab (both Android), or .ipa (iOS) file. Copy and paste the link into your browser to download the file.
想要在构建完成后立即以编程方式收到通知吗?以下是如何使用 webhooks 进行设置。
¥Want to be notified programmatically as soon as your build is done? Here's how you can set that up with webhooks.
¥ Test it on your device or simulator
¥Android
要在 Android 模拟器上运行它,首先通过运行 expo build:android -t apk
使用 apk 标志构建项目,然后将 .apk 拖放到模拟器中。
¥To run it on your Android Emulator, first build your project with the apk flag by running expo build:android -t apk
, and drag and drop the .apk into the emulator.
要在 Android 设备上运行它,请确保你已随 adb
安装了 Android 平台工具,然后只需使用 你的设备上启用了 USB 调试 运行 adb install app-filename.apk
并插入设备即可。
¥To run it on your Android device, make sure you have the Android platform tools installed along with adb
, then just run adb install app-filename.apk
with USB debugging enabled on your device and the device plugged in.
¥iOS
要在 iOS 模拟器上运行它,请首先通过运行 expo build:ios -t simulator
使用模拟器标志构建项目,然后下载包含构建完成时打印的链接的工件。要安装生成的 tar.gz 文件,请将其解压缩并将其拖放到你的 iOS 模拟器中。如果你想从命令行安装它,请运行 tar -xvzf your-app.tar.gz
解压文件,打开模拟器,然后运行 xcrun simctl install booted <path to .app>
。
¥To run it on your iOS Simulator, first build your project with the simulator flag by running expo build:ios -t simulator
, then download the artifact with the link printed when your build completes. To install the resulting tar.gz file, unzip it and drag and drop it into your iOS Simulator. If you'd like to install it from the command line, run tar -xvzf your-app.tar.gz
to unpack the file, open a simulator, then run xcrun simctl install booted <path to .app>
.
要使用 Apple TestFlight 测试设备版本,请将 .ipa 文件下载到本地计算机。在 应用商店连接 中,单击加号图标并创建一个新应用。确保你的 bundleIdentifier
与你在 app.json 中放置的内容匹配。现在,你需要使用 Xcode 或 运输车(以前称为 Application Loader)上传从 expo build:ios
获得的 .ipa。完成此操作后,你可以在 Activity
下检查构建的状态。处理应用可能需要 10-15 分钟才能显示在可用版本中。
¥To test a device build with Apple TestFlight, download the .ipa file to your local machine. Within App Store Connect, click the plus icon and create a New App. Make sure your bundleIdentifier
matches what you have placed in app.json. Now, you need to use Xcode or Transporter (previously known as Application Loader) to upload the .ipa you got from expo build:ios
. Once you do that, you can check the status of your build under Activity
. Processing an app can take 10-15 minutes before it shows up under available builds.
¥ Submit it to the appropriate store
阅读有关 将应用上传到 Apple App Store 和 Google Play 的文档。
¥Read the documentation on Uploading Apps to the Apple App Store and Google Play.
¥ Update your app
要更新你的应用,请使用 Expo CLI 中的经典更新的 expo publish
命令。安装应用的物理设备将在下次在该设备上打开应用时下载新的 JavaScript 更新。为了确保你的应用用户在下载 JavaScript 更新时获得无缝体验,你可能需要启用 后台 JS 下载。
¥To update your app, use the Classic Update's expo publish
command from the Expo CLI. The physical device on which the app is installed will download the new JavaScript update the next time the app is open on that device. To ensure your app users have a seamless experience downloading JavaScript updates, you may want to enable background JS downloads.
你可能想要重建并重新提交原生二进制文件的原因有几个:
¥There are a couple of reasons why you might want to rebuild and resubmit the native binaries:
如果你想更改原生元数据,例如应用的名称或图标
¥If you want to change native metadata like the app's name or icon
如果你升级到应用的较新 SDK 版本(这需要新的原生代码)
¥If you upgrade to a newer SDK version of the app (which requires new native code)
你必须更新 app.json 中应用的 versionCode
和 buildNumber
。阅读 对你的应用文档进行版本控制 了解更多详细信息。
¥You have to update the app's versionCode
and buildNumber
in app.json. Read the Versioning Your app documentation for more details.
我们还建议你浏览 应用配置文档 以了解你可以更改的所有属性。例如图标、深度链接 URL 方案、添加或删除手机/平板电脑支持等。
¥We also recommend you go through app config documentation to get an idea of all the properties you can change. Such as the icons, deep linking URL scheme, add or remove handset/tablet support, and so on.