了解面向开发者和面向用户的应用版本以及如何自动管理它们。
在本章中,我们将配置示例应用以自动递增面向开发者的应用版本。在我们在接下来的两章中深入生产构建之前,了解它将会很有用。
¥In this chapter, we'll configure our example app to auto-increment the developer-facing app version. 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
。
¥Developer-facing value: Represented by versionCode
for Android and buildNumber
for iOS.
面向用户的价值:由 version
app.config.js 代表。
¥User-facing value: Represented by version
app.config.js.
Google Play 商店和 Apple 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 developer and user 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
来手动管理面向开发者的值。
¥We can manually manage developer-facing values by adding android.versionCode
and ios.buildNumber
in app.config.js.
{
"ios": {
"buildNumber": "1"
%%placeholder-start%%... %%placeholder-end%%
},
"android": {
"versionCode": "1"
}
%%placeholder-start%%... %%placeholder-end%%
}
手动添加这些值后,我们每次都需要在创建新的生产版本之前更新它们,否则我们将遇到提交失败的错误。但是,为了消除出现错误的可能性,我们可以使用下一节中的 EAS Build 来自动化此过程
¥After manually adding these values, we need to update them every time before creating a new production build otherwise we will run into a failed submission error. However, to eliminate the chances of running into the error, we can automate this process using EAS Build in the next section
注意:EAS 不处理面向用户的版本号。相反,我们在提交生产应用以供审核之前在应用商店开发者门户中进行定义。
¥Note: The user-facing version number is not handled by EAS. Instead, we define that in the app store developer portals before submitting our production app for review.
¥Automate app version management with EAS Build
EAS Build 可以帮助我们利用 远程版本资源 自动化这些值。此功能会自动增加面向开发者的值,并在发布新的生产版本时跟踪它们。
¥EAS Build can assist us in automating these values by utilizing the remote version resource. This feature automatically increments developer-facing values and keeps track of them whenever a new production release is made.
在 eas.json 中:
¥In eas.json:
添加 cli.appVersionSource
并将其设置为 remote
¥Add cli.appVersionSource
and set it to remote
将 build.production.autoIncrement
设置为 true
:
¥Set build.production.autoIncrement
to true
:
{
"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 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
命令:
¥In the terminal window, run the eas build:version:set
command:
eas build:version:set
在提示时选择平台(Android 或 iOS)。
¥Select the platform (Android or iOS) when prompted.
当提示“你是否要立即将应用版本源设置为远程?”时,选择“是”。这会将 eas.json 中的 cli.appVersionSource
设置为 remote
。
¥When prompted Do you want to set app version source to remote now?, select yes. This will set the cli.appVersionSource
to remote
in eas.json.
当提示“你想用哪个版本初始化它?”时,输入你在应用商店中设置的最后一个版本号。
¥When prompted What version would you like to initialize it with?, enter the last version number that you have set in the app stores.
完成这些步骤后,应用版本将远程同步到 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.