在本地创建发布版本

学习如何在本地为你的 Expo 应用创建发布(生产)版本。


要在本地创建你的应用发布版本(也称为生产版本),你需要在计算机上遵循不同的步骤,并使用创建任何原生应用所需的工具。本指南提供了创建 Android 和 iOS 所需的步骤。

🌐 To create your app's release build (also known as production build) locally, you need to follow separate steps on your computer and use the tools required to create any native app. This guide provides the necessary steps for Android and iOS.

安卓

🌐 Android

在本地为 Android 创建发布版本需要使用 上传密钥 对其进行签名,并生成一个 Android 应用包(.aab)。请按照以下步骤操作:

🌐 Creating a release build locally for Android requires signing it with an upload key and generating an Android Application Bundle (.aab). Follow the steps below:

先决条件

🌐 Prerequisites

  • 已安装 OpenJDK 发行版 以访问 keytool 命令
  • android 目录已生成。如果你正在使用 CNG,请运行 npx expo prebuild 来生成它。

1

创建上传密钥

🌐 Create an upload key

已经使用 EAS Build 创建了构建?下载你的凭证并跳到下一步。

如果你已经使用 EAS Build 创建了一个构建,请按照以下步骤下载凭证,其中包含上传密钥及其密码、密钥别名和密钥密码:

🌐 If you've already created a build with EAS Build, follow the steps below to download the credentials, which contains the upload key and its password, key alias, and key password:

  1. 在你的终端中,运行 eas credentials -p android 并选择构建配置文件。
  2. 选择 credentials.json > 从 EAS 下载凭证到 credentials.json
  3. 将下载的 keystore.jks 文件移动到 android/app 目录下。
  4. credentials.json 中复制用于上传 keystore 的密码、密钥别名和密钥密码,因为你在下一步中将需要它们。

在你的 Expo 项目目录中,运行以下 keytool 命令以创建上传密钥:

🌐 Inside your Expo project directory, run the following keytool command to create an upload key:

Terminal
sudo keytool -genkey -v -keystore my-upload-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

运行此命令后,系统会提示你输入密钥库的密码。此密码将保护上传密钥。请记住你在此输入的密码,因为下一步你将需要使用它。

🌐 After running this command, you will be prompted to enter a password for the keystore. This password will protect the upload key. Remember the password you enter here, as you'll need it in the next step.

此命令还会在你的项目目录中生成名为 my-upload-key.keystore 的密钥库文件。将其移动到 android/app 目录下。

🌐 This command also generates the keystore file named my-upload-key.keystore in your project directory. Move it to the android/app directory.

警告 如果你将 android 目录提交到像 Git 这样的版本控制系统,请不要提交此 keystore 文件。它包含你的上传密钥,应保持私密。

2

更新 Gradle 变量

🌐 Update gradle variables

打开 android/gradle.properties 文件,在文件末尾添加以下 gradle 变量。将 ***** 替换为你在上一步中提供的正确密钥库和密钥密码。

🌐 Open android/gradle.properties file and add the following gradle variables at the end of the file. Replace the ***** with the correct keystore and key password that you provided in the previous step.

这些变量包含有关你的上传密钥的信息:

🌐 These variables contain information about your upload key:

android/gradle.properties
# If you've downloaded the credentials from `eas credentials` command, see comments below for each value. MYAPP_UPLOAD_STORE_FILE=my-upload-key.keystore # Path to the "keystore" file MYAPP_UPLOAD_KEY_ALIAS=my-key-alias # Replace with value of the `keystore.keyAlias` field in the credentials.json file MYAPP_UPLOAD_STORE_PASSWORD=***** # Replace with value of the `keystore.password` field in the credentials.json file MYAPP_UPLOAD_KEY_PASSWORD=***** # Replace with value of the `keystore.keyPassword` field in the credentials.json file

警告 如果你将 android 目录提交到像 Git 这样的版本控制系统,不要提交上述信息。相反,请在你的电脑上创建一个 ~/.gradle/gradle.properties 文件,并将上述变量添加到该文件中。

3

将签名配置添加到 build.gradle

🌐 Add signing config to build.gradle

打开 android/app/build.gradle 文件,并添加以下配置:

🌐 Open android/app/build.gradle file and add the following configuration:

4

Generate release Android Application Bundle (aab)

Navigate inside the android directory and create a release build in .aab format by running Gradle's bundleRelease command:

Terminal
cd android

./gradlew app:bundleRelease

此命令将在 android/app/build/outputs/bundle/release 目录下生成 app-release.aab。

🌐 This command will generate app-release.aab inside the android/app/build/outputs/bundle/release directory.

5

手动提交应用到 Google Play 控制台

🌐 Manual app submission to Google Play Console

在首次提交 .aab 文件时,Google Play 商店需要手动提交应用。

🌐 Google Play Store requires manual app submission when submitting the .aab file for the first time.

手动提交 Android 应用

按照 FYI 指南中的步骤,首次手动将你的应用提交到 Google Play 商店。

iOS

要在本地为 Apple App Store 创建 iOS 发布版本,你需要使用 Xcode,它可以通过 App Store Connect 处理签名和提交流程。

🌐 To create an iOS release build locally for Apple App Store, you need to use Xcode which handles the signing and submission process via App Store Connect.

先决条件

🌐 Prerequisites

  • 付费苹果开发者会员
  • 在你的电脑上安装了 Xcode
  • ios 目录已生成。如果你正在使用 CNG,请运行 npx expo prebuild 来生成它。

1

在 Xcode 中打开 iOS 工作区

🌐 Open iOS workspace in Xcode

在你的 Expo 项目目录中,运行以下命令以在 Xcode 中打开 your-project.xcworkspace

🌐 Inside your Expo project directory, run the following command to open your-project.xcworkspace in Xcode:

Terminal
xed ios

在 Xcode 中打开 iOS 项目后:

🌐 After opening the iOS project in Xcode:

  1. 从左侧边栏中选择你应用的工作区。
  2. 转到 Signing & Capabilities(签名与功能) 并选择 All(全部)Release(发布)
  3. 签名 > 团队 下,确保已选择你的 Apple 开发者团队。Xcode 将生成自动管理的配置描述文件和签名证书。

2

配置发布方案

🌐 Configure a release scheme

要配置应用的发布方案:

🌐 To configure your app's release scheme:

  1. 从菜单栏中,打开 产品 > 方案 > 编辑方案
  2. 从侧边栏中选择 运行,然后使用下拉菜单将 构建配置 设置为 发布

3

构建应用以发布

🌐 Build app for release

要构建用于发布的应用,请在菜单栏中打开 产品 > 构建。此步骤将构建用于发布的应用二进制文件。

🌐 To build your app for release, From the menu bar, open Product > Build. This step will build your app binary for release.

4

使用 App Store Connect 提交应用

🌐 App submission using App Store Connect

构建完成后,你可以通过 App Store Connect 将你的应用分发到 TestFlight 或提交到 App Store:

🌐 Once the build is complete, you can distribute your app to TestFlight or submit it to the App Store using App Store Connect:

  1. 从菜单栏打开 产品 > 存档
  2. 归档 下,从右侧边栏点击 分发应用
  3. 点击 App Store Connect 并按照窗口中显示的提示操作。此步骤将创建一个应用商店记录并将你的应用上传到 App Store。
  4. 现在你可以登录你的 App Store Connect 账户,在“应用”中选择你的应用,然后通过 TestFlight 提交进行测试,或者按照 App Store Connect 仪表板中的步骤准备应用最终发布。