为 Android 创建生产版本

了解为 Android 创建生产版本和自动化发布过程的过程。


在本章中,我们将创建示例应用的生产版本并将其提交到 Google Play 商店。我们还将探讨如何自动化创建和发布新应用版本。

🌐 In this chapter, we'll create our example app's production version and submit it to the Google Play Store. We'll also explore how to automate the creation and release of new app versions.

观看:为 Android 创建和发布生产版本
观看:为 Android 创建和发布生产版本

先决条件

🌐 Prerequisites

要在 Google Play 商店上发布和分发应用,我们需要:

🌐 To publish and distribute an app on the Google Play Store, we need:

  • Google Play 开发者账号: 必须拥有付费开发者账号。有关如何设置账号的详细信息,请访问 Google Play 注册页面
  • Google 服务账号密钥: 我们需要一个 Google 服务账号的邮箱和 JSON 密钥来自动化应用提交流程。请按照我们指南中关于创建 Google 服务账号密钥或从现有账号下载 的详细说明操作,然后返回本指南。 这是可选的,但对于自动发布流程 是必需的。
  • 生产构建配置: 确保在你的 eas.json 中存在 production 构建配置,它是默认添加的。

Android 的生产版本

🌐 Production build for Android

一个生产 Android 构建采用 .aab 格式,这种格式经过优化,可用于在 Google Play 商店分发。与 .apk 构建不同,.aab 文件只能通过 Google Play 商店分发和安装。

🌐 A production Android build has a .aab format which is optimized for distribution on the Google Play Store. Unlike .apk builds, .aab files can only be distributed and installed through the Google Play Store.

1

创建生产版本

🌐 Create a production build

要使用默认的 production 配置创建 Android 生产构建,请打开终端并执行以下命令。由于 production 已在 EAS 配置中设置为默认配置,因此无需使用 --profile 标志显式指定它。

🌐 To create an Android production build using the default production profile, open your terminal and execute the following command. Since production is set as the default profile in the EAS configuration, there is no need to specify it explicitly with the --profile flag.

Terminal
eas build --platform android

上述命令将把构建排入队列。在 EAS 仪表板中注意 版本代码 是自动递增的。

🌐 The above command will queue the build. Notice in the EAS dashboard that the Version Code is auto-incremented.

2

在 Google Play 控制台创建一个应用

🌐 Create an app on the Google Play Console

要首次将应用上传到 Google Play 商店,我们需要:

🌐 To upload the app to the Google Play Store for the first time, we need to:

  • 前往 Google Play 控制台。
  • 首页,点击创建应用来制作一个新应用。
  • 填写我们的应用详情,然后点击 创建应用 按钮。

3

发布内部测试版本

🌐 Release an internal testing version

在 Google Play 控制台创建应用后,它会将我们重定向到应用的仪表板屏幕。我们需要准备应用的内部测试版本。

🌐 After the app is created on Google Play Console, it redirects us to the app's Dashboard screen. We need to prepare an internal test version of our app.

  • 仪表板 上点击 立即开始测试
  • 创建一个电子邮件列表,包含 内部测试 > 内部测试版本的测试人员 下的用户。
  • Google Play 控制台提示我们创建内部测试版本。
  • 要创建新版本,请转到 仪表板 并点击 创建新版本。你会首先注意到签名密钥已由 Google Play 控制台在 应用完整性 下自动生成。

4

上传应用二进制文件

🌐 Upload the app binary

在 EAS 创建生产构建之后:

🌐 After EAS has created a production build:

  • 打开 EAS 仪表板,然后点击 下载 获取 .aab 文件。
  • 返回 Google Play 控制台,然后进入 测试与发布 > 测试 > 内部测试
  • 应用包 下,点击 上传 以添加 .aab 文件。然后,提供我们应用的发布详情并点击 下一步
  • 在接下来的屏幕上,点击 保存并发布

5

分享内部发布版本

🌐 Share the internal release version

曲目摘要下,我们看到最新版本显示了一个临时的应用名称。这是因为我们的应用尚未经过审核。

🌐 Under Track Summary, we see that the latest release shows a temporary app name. This is because our app is not reviewed yet.

版本下,我们可以看到该应用可供内部测试人员使用。要与测试团队共享该应用,请执行以下操作:

🌐 Under Releases, we see that the app is available to internal testers. To share the app with a team of testers:

  • 切换到 Releases 旁边的 测试人员 标签。
  • 点击 如何让测试人员加入你的测试 下的 复制链接。你可以使用此链接通过电子邮件或消息与你的测试团队分享。
  • 在设备上打开测试邮件,并按照步骤下载应用。
  • 测试邮箱持有者需要接受邀请,一旦接受,应用就可以安装到设备上。

信息 提示:要在 Play 商店发布应用,请在 Google 控制台中完成 设置你的应用 下的步骤。这些步骤是在第一次将应用发布到 Play 商店之前必须完成的。你需要提供的信息包括隐私政策链接、目标受众、数据安全等内容。

完整的应用商店列表:要为应用准备商店列表,请参阅 创建应用商店资源 了解如何创建截图和预览。

推广测试版本

要在 Google Play 商店控制台中将我们的内部测试发布版本推广到 alpha:

🌐 To promote our internal test release version to alpha, in Google Play Store Console:

  • 测试与发布 下,进入 测试 > 封闭测试
  • 点击 Closed testing - Alpha 旁边的 管理版本

6

添加 Google 服务账号权限密钥

🌐 Add Google Service Account permissions key

信息 提示:在按照本节的步骤操作之前,请查看关于创建 Google 服务账号密钥或从现有账号下载的指南。

从现在起,我们可以使用 EAS Submit 来自动化发布,避免手动操作。为此,我们需要将服务账户密钥添加到我们项目的凭据中。

🌐 From now on, we can use EAS Submit to automate releases and avoid the manual process. To do that, we need to add the service account key to our project's credentials.

按照 Google 服务账号指南的步骤操作后,我们可以将下载的 JSON 密钥上传到 EAS 仪表板:

🌐 After following the Google Service Account guide steps, we can upload the downloaded JSON key to EAS dashboard:

  • 进入你项目的 EAS 仪表板,点击 Credentials,在 Android 下,点击你应用的 Application identifier
  • 服务凭据 下,点击 添加 Google 服务账户密钥
  • 更改 Google 服务账户密钥 下,确保选择 上传新密钥 并上传下载的 JSON 密钥。这将把密钥添加到你项目的凭据中。

7

内部发布

🌐 Internal release

让我们在 eas.json 中将轨道设置为 internal

🌐 Let's set the track to internal in eas.json.

  • submit.production 配置文件下,将 track 设置为 internal
{ %%placeholder-start%%... %%placeholder-end%% "submit": { "production": { "android": { "track": "internal" } } } }

在上面的代码片段中,我们添加了 track 属性并将其值设置为 internal。这将使 eas submit 命令能够上传我们的生产版本并在 Google Play 商店进行内部测试发布。

🌐 In the above snippet, we're adding track property and setting its value to internal. This will enable the eas submit command to upload our production build and release it for internal testing on the Google Play Store.

  • 现在运行 eas submit 命令来发布一个新的内部测试版本:
Terminal
eas submit --platform android
  • 此命令将自动在 Google Play 控制台中创建一个新的内部发布版本:

8

正式发布

🌐 Production release

要发布应用到生产环境:

🌐 To release the app for production:

  • eas.json 中将 track 的值改为 production
{ %%placeholder-start%%... %%placeholder-end%% "submit": { "production": { "android": { "track": "production" } } } }
  • 我们也可以使用相同的 EAS Build 来进行内部测试发布。运行 eas submit 命令将其发布到 Play 商店:
Terminal
eas submit --platform android
  • 要创建一个版本并将我们的应用提交到 Google Play 商店的审核流程,我们需要进入 测试与发布 > 正式发布,然后在 版本 下选择我们想要提交审核的构建。

9

自动发布

🌐 Automated release

在以后的后续版本中,我们可以通过使用 eas build--auto-submit 标志,将构建创建和 Play 商店提交合并为一个步骤,从而简化流程:

🌐 For subsequent releases in future, we can streamline the process by combining build creation and Play Store submission into a single step by using the --auto-submit flag with eas build:

Terminal
eas build --platform android --auto-submit

概括

🌐 Summary

Chapter 8: Create a production build for Android

We successfully created a production-ready Android build, discussed manual and automated uploading to Google Play Store using eas submit, and automated the release process with the --auto-submit.

In the next chapter, learn about the process of creating a production build for iOS.

Next: Create a production build for iOS