管理不同的应用版本
了解面向开发者和面向用户的应用版本,以及 EAS Build 如何自动管理面向开发者的版本。
在本章中,我们将学习 EAS Build 如何自动管理面向开发者的 Android 和 iOS 应用版本。在深入研究接下来的两章的生产构建之前,了解这些内容会非常有用。
🌐 In this chapter, we'll learn how EAS Build automatically manages the developer-facing app version for Android and iOS. Learning about it will be useful before we dive into production build in the next two chapters.

了解面向开发者和面向用户的应用版本
🌐 Understanding developer-facing and user-facing app versions
应用版本由两个值组成:
🌐 An app version is composed of two values:
- 面向开发者的值:在 Android 上由
versionCode表示,在 iOS 上由buildNumber表示。 - 面向用户的值:由
versionapp.config.js 表示。
谷歌 Play 商店和苹果 App Store 都依赖面向开发者的值来识别每个独特的构建。例如,如果我们上传一个应用,应用版本为 1.0.0 (1)(这是用户可见值和开发者可见值的组合),我们就无法向应用商店提交另一个具有相同应用版本的构建。提交重复应用版本号的构建会导致提交失败。
🌐 Both Google Play Store and Apple App Store rely on developer-facing values to identify each unique build. For example, if we upload an app with the app version 1.0.0 (1) (which is a combination of user-facing and developer-facing values), we cannot submit another build to the app stores with the same app version. Submitting builds with duplicate app version numbers results in a failed submission.
下面通过 app.config.js 中的 android.versionCode 和 ios.buildNumber 展示了手动管理面向开发者的值的示例演示。我们不必手动添加或管理这些值,因为 EAS Build 会为我们自动处理。
🌐 An example demonstration of manually managing developer-facing values is shown below by android.versionCode and ios.buildNumber in app.config.js. We don't have to add or manage these values manually since EAS Build automates this for us.
{ ios: { buildNumber: 1 %%placeholder-start%%... %%placeholder-end%% }, android: { versionCode: 1 } %%placeholder-start%%... %%placeholder-end%% }
注意:EAS 不会处理 面向用户的版本号。相反,我们会在将生产应用提交审核之前,在应用商店开发者门户中进行定义。
使用 EAS Build 自动管理应用版本
🌐 Automatic app version management with EAS Build
默认情况下,EAS 构建会协助自动化开发者相关的数值。它利用远程版本来源在每次发布新生产版本时自动递增开发者相关的数值。
🌐 By default, EAS Build assists in automating developer-facing values. It utilizes the remote version source to automatically increment developer-facing values whenever a new production release is made.
当我们使用 eas init 命令初始化项目时,EAS CLI 会自动在 eas.json 中添加以下属性:
🌐 When we initialized the project with eas init command, the EAS CLI automatically added the following properties in eas.json:
cli.appVersionSource被设置为remotebuild.production.autoIncrement已设置为true
你可以在项目的 eas.json 中查看它们:
🌐 You can view them in your project's eas.json:
{ "cli": { %%placeholder-start%%... %%placeholder-end%% "appVersionSource": "remote" }, "build": { "production": { "autoIncrement": true } } %%placeholder-start%%... %%placeholder-end%% }
在接下来的两章中,当我们创建新的生产版本时,Android 的 versionCode 和 iOS 的 buildNumber 将会自动递增。
🌐 When we create a new production build in the next two chapters, the versionCode for Android and buildNumber for iOS will increment automatically.
将已发布应用的面向开发者的应用版本同步到 EAS
如果你的应用已经在应用商店发布,面向开发者的应用版本已经设置好。在将此应用迁移到使用 EAS Build 时,请按照以下步骤同步这些应用版本:
🌐 If your app is already published in the app stores, the developer-facing app versions are already set. When migrating this app to use EAS Build, follow the steps below to sync those app versions:
- 在终端窗口中,运行
eas build:version:set命令:
- eas build:version:set- 在提示时选择平台(Android 或 iOS)。
- 当出现提示 你现在想将应用版本来源设置为远程吗? 时,选择 是。这将在 eas.json 中将
cli.appVersionSource设置为remote。 - 当提示 你想用哪个版本初始化它? 时,输入你在应用商店中设置的最后一个版本号。
完成这些步骤后,应用版本将会远程同步到 EAS Build。你可以在 eas.json 中将 build.production.autoIncrement 设置为 true。当你创建新的生产版本时,versionCode 和 buildNumber 将从此自动递增。
🌐 After these steps, the app versions will be synced to EAS Build remotely. You can set build.production.autoIncrement to true in eas.json. When you create a new production build, the versionCode and buildNumber will be automatically incremented from now on.
概括
🌐 Summary
Chapter 7: Manage different app versions
We successfully explored app versioning differences, addressed the importance of unique app versions to prevent store rejections, and enabled automated version updates in eas.json for production builds.
In the next chapter, learn about the process of creating a production build for Android.