管理不同的应用版本

了解面向开发者和面向用户的应用版本,以及 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.

Watch: Automating app version code
Watch: Automating app version code

了解面向开发者和面向用户的应用版本

¥Understanding developer-facing and user-facing app versions

应用版本由两个值组成:

¥An app version is composed of two values:

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 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.versionCodeios.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.

app.config.js
{
  ios: {
    buildNumber: 1
    %%placeholder-start%%... %%placeholder-end%%
  },
  android: {
    versionCode: 1
  }
  %%placeholder-start%%... %%placeholder-end%%
}

注意:面向用户的版本号 不由 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.

使用 EAS Build 自动管理应用版本

¥Automatic app version management with EAS Build

默认情况下,EAS Build 协助自动化面向开发者的值。它利用 远程版本源 在发布新的生产版本时自动增加面向开发者的值。

¥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:

你可以在项目的 eas.json 中查看它们:

¥You can view them in your project's eas.json:

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.

Syncing developer-facing app versions for already published apps to 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 命令:

    ¥In the terminal window, run the eas build:version:set command:

Terminal
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。从现在开始,当你创建新的生产版本时,versionCodebuildNumber 将自动递增。

¥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.

Next: Create a production build for Android