了解如何在本地为你的 Expo 应用创建生产版本。
要在本地创建应用的生产版本(也称为发布版本),你需要在计算机上执行单独的步骤并使用创建任何原生应用所需的工具。本指南提供了 Android 和 iOS 的必要步骤。
¥To create your app's production build (also known as release 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 production 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
命令
¥OpenJDK distribution installed to access the keytool
command
android 目录已生成。如果你使用的是 CNG,则运行 npx expo prebuild
来生成它。
¥android directory generated. If you are using CNG, then run npx expo prebuild
to generate it.
1
¥Create an upload key
如果你已经使用 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:
在你的终端中,运行 eas credentials -p android
并选择构建配置文件。
¥In your terminal, run eas credentials -p android
and select the build profile.
选择 credentials.json > 将凭证从 EAS 下载到 credentials.json。
¥Select credentials.json > Download credentials from EAS to credentials.json.
将下载的 keystore.jks 文件移动到 android/app 目录。
¥Move the downloaded keystore.jks file to the android/app directory.
从 credentials.json 复制上传密钥库密码、密钥别名和密钥密码的值,因为你将在下一步中需要它们。
¥Copy the values for the upload keystore password, key alias, and key password from the credentials.json as you will need them in the next step.
在你的 Expo 项目目录中,运行以下 keytool
命令来创建上传密钥:
¥Inside your Expo project directory, run the following keytool
command to create an upload key:
-
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 等版本控制系统,请不要提交此密钥库文件。它包含你的上传密钥,应保密。
2
¥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:
MYAPP_UPLOAD_STORE_FILE=my-upload-key.keystore
MYAPP_UPLOAD_KEY_ALIAS=my-key-alias
MYAPP_UPLOAD_STORE_PASSWORD=*****
MYAPP_UPLOAD_KEY_PASSWORD=*****
如果你将 android 目录提交给 Git 等版本控制系统,请不要提交上述信息。相反,在你的计算机上创建一个 ~/.gradle/gradle.properties 文件并将上述变量添加到此文件。
3
4
¥Generate release Android Application Bundle (aab)
在 android 目录中导航并通过运行 Gradle 的 bundleRelease
命令创建 .aab 格式的生产版本:
¥Navigate inside the android directory and create a production build in .aab format by running Gradle's bundleRelease
command:
-
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
¥Manual app submission to Google Play Console
首次提交 .aab 文件时,Google Play Store 要求手动提交应用。
¥Google Play Store requires manual app submission when submitting the .aab file for the first time.
按照 FYI 指南中的步骤,首次手动将你的应用提交到 Google Play Store。
¥iOS
要在本地为 Apple App Store 创建 iOS 生产版本,你需要使用 Xcode,它通过 App Store Connect 处理签名和提交过程。
¥To create an iOS production build locally for Apple App Store, you need to use Xcode which handles the signing and submission process via App Store Connect.
¥Prerequisites
付费 Apple 开发者会员资格
¥Paid Apple Developer membership
计算机上的 Xcode 安装
¥Xcode installed on your computer
ios 目录已生成。如果你使用的是 CNG,则运行 npx expo prebuild
来生成它。
¥ios directory generated. If you are using CNG, then run npx expo prebuild
to generate it.
1
¥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:
-
xed ios
在 Xcode 中打开 iOS 项目后:
¥After opening the iOS project in Xcode:
从左侧边栏中选择你的应用的工作区。
¥From the sidebar on the left, select your app's workspace.
转到签名和功能并选择全部或发布。
¥Go to Signing & Capabilities and select All or Release.
在签名 > 团队下,确保选择了你的 Apple 开发者团队。Xcode 将生成自动管理的配置文件和签名证书。
¥Under Signing > Team, ensure your Apple Developer team is selected. Xcode will generate an automatically managed Provisioning Profile and Signing Certificate.
2
3
4
¥App submission using App Store Connect
构建完成后,你可以将应用分发到 TestFlight 或使用 App Store Connect 将其提交到 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:
从菜单栏中,打开产品 > 存档。
¥From the menu bar, open Product > Archive.
在存档下,单击右侧边栏中的分发应用。
¥Under Archives, click Distribute App from the right sidebar.
单击 App Store Connect 并按照窗口中显示的提示进行操作。此步骤将创建应用商店记录并将你的应用上传到应用商店。
¥Click App Store Connect and follow the prompts shown in the window. This step will create an app store record and upload your app to the App Store.
现在你可以转到你的 App Store Connect 账户,在 Apps 下选择你的应用,然后使用 TestFlight 提交测试,或者按照 App Store Connect 仪表板中的步骤准备最终发布。
¥Now you can go to your App Store Connect account, select your app under Apps, and submit it for testing using TestFlight or prepare it for final release by following the steps in the App Store Connect dashboard.