了解为 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.
¥Prerequisites
要在 Google Play 商店上发布和分发应用,我们需要:
¥To publish and distribute an app on the Google Play Store, we need:
Google Play 开发者账户:必须有付费开发者账户。有关设置的详细信息,请访问 Google Play 注册页面。
¥Google Play Developer Account: Must have a paid developer account. For details on setting one up, visit the Google Play sign-up page.
谷歌服务账户:我们需要 Google 服务账户电子邮件和 JSON 密钥来自动执行应用提交过程。请按照 创建 Google 服务账户 指南中的详细说明进行操作,然后返回到本指南。这是可选的,但对于自动化发布过程是必需的。
¥Google Service Account: We'll need a Google Service Account email and JSON key to automate the app submission process. Follow the detailed instructions in our guide on creating a Google Service Account, then return to this guide. This is optional but required for automating the release process.
生产构建简介:确保你的 eas.json 中存在 production
构建配置文件,该配置文件是默认添加的。
¥Production build profile: Ensure that a production
build profile is present in your eas.json, which is added by default.
¥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.
-
eas build --platform android
上面的命令将对构建进行排队。请注意,Expo 仪表板中的版本代码是自动递增的。
¥The above command will queue the build. Notice in the Expo dashboard that the Version Code is auto-incremented.
2
¥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 仪表板。
¥Go to the Google Play dashboard.
在主页上,单击“创建应用”以创建一个新应用。
¥On the Home page, click Create app to make a new app.
填写我们的应用详细信息,然后单击“创建应用”按钮。
¥Fill out our app details and click the Create app button.
3
¥Release an internal testing version
在 Google Play Console 上创建应用后,它会将我们重定向到应用的仪表板屏幕。我们需要准备我们的应用的内部测试版本。
¥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.
单击仪表板上的立即开始测试。
¥Click Start testing now on the Dashboard.
在内部测试 > 测试人员下创建内部测试版本的用户电子邮件列表。
¥Create an email list of users under Internal Testing > Testers for the internal testing release.
Google Play Console 提示我们创建一个版本。
¥Google Play Console prompts us to create a Release.
要创建新版本,请转至版本并单击创建新版本。
¥To create a new release, go to Releases and click Create new release.
要存储签名密钥,请转至应用完整性 > 应用包,然后单击选择签名密钥 > 使用 Google 生成的密钥。
¥To store the signing key, go to App integrity > App bundles and click Choose signing key > Use Google-generated key.
4
¥Upload the app binary
EAS 创建生产版本后:
¥After EAS has created a production build:
打开 EAS 仪表板并单击“下载”以获取 .aab 文件。
¥Open the EAS dashboard and click on Download to get the .aab file.
返回 Google Play 管理中心并转到应用包。单击“上传”以添加 .aab。
¥Return to the Google Play Console and go to App bundles. Click on Upload to add the .aab.
提供我们的应用的发布详细信息,然后单击“下一步”。
¥Provide the release details for our app and click on Next.
在接下来的屏幕上,单击“保存并发布”。
¥On the following screen, click on Save and publish.
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:
打开内部测试仪表板,然后单击查看版本详细信息。
¥Open the Internal testing dashboard, then click on View release details.
单击测试人员如何加入测试下的复制链接。
¥Click on copy link under How testers join your test.
在设备上,打开测试电子邮件并按照步骤下载应用。
¥On the device, open the test email and follow the steps to download the app.
测试电子邮件持有者需要接受邀请,一旦接受,应用就可以安装在设备上。
¥The testing email holder needs to accept the invite, and once accepted, the app can be installed on the device.
提示:要在 Play 商店上发布应用,请在 Google 仪表板中完成设置应用下的步骤。首次在 Play 商店上发布应用之前需要执行这些步骤。你必须提供隐私政策链接、目标受众、数据安全等详细信息。
完整的应用商店列表:要准备应用的商品详情,请参阅 创建应用商店资源 了解如何创建屏幕截图和预览。
¥Complete app store listing: To prepare the app for store listing, see Create app store assets on how to create screenshots and previews.
要将我们的内部测试版本升级为 alpha,请在 Google Play 商店控制台中执行以下操作:
¥To promote our internal test release version to alpha, in Google Play Store Console:
转到内部测试并单击“升级发布”。
¥Go to internal testing and click Promote release.
打开下拉菜单,然后单击“关闭测试”>“关闭测试” - Α。
¥Open the dropdown menu and click Closes testing > Closed testing - Alpha.
6
¥Add Google Service Account permissions key
从现在开始,我们可以使用 EAS 提交 来自动化发布并避免手动过程。为此,我们需要将服务账户密钥添加到项目的 eas.json 中。
¥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 eas.json.
遵循 Google 服务账户指南步骤后,我们可以使用下载的 JSON 密钥:
¥After following the Google Service Account guide steps, we can use the downloaded JSON key:
打开我们的项目并将 JSON 文件从 Google 服务账户复制到项目的根目录。
¥Open our project and copy the JSON file from the Google Service Account to the project's root directory.
为了保护敏感数据,请通过在我们的 .gitignore 中列出该文件来确保将其排除在版本控制之外。
¥To secure sensitive data, ensure this file is excluded from version control by listing it in our .gitignore.
7
¥Internal release
让我们在 eas.json 中添加 Google 服务账户文件路径的路径。
¥Let's add the path to the Google Service Account file path in eas.json.
在 submit.production
配置文件下,添加 android.serviceAccountKeyPath
和相对文件路径作为其值:
¥Under submit.production
profile, add android.serviceAccountKeyPath
and the relative file path as its value:
{
%%placeholder-start%%... %%placeholder-end%%
"submit": {
"production": {
"android": {
"serviceAccountKeyPath": "./service-account-file.json",
"track": "internal"
}
}
}
}
在上面的代码片段中,我们还添加了 track
属性并将其值设置为 internal
。这将使 eas submit
命令能够上传我们的生产版本并将其发布到 Google Play 商店进行内部测试。
¥In the above snippet, we're also 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
命令发布新的内测版本:
¥Now run the eas submit
command to release a new internal testing version:
-
eas submit --platform android
此命令将自动在 Google Play Console 中创建新的内部发布版本:
¥This command will automatically create a new internal release version in Google Play Console:
8
¥Production release
发布应用以进行生产:
¥To release the app for production:
将 eas.json 中 track
的值更改为 production
:
¥Change the value for track
to production
in eas.json:
{
%%placeholder-start%%... %%placeholder-end%%
"submit": {
"production": {
"android": {
"serviceAccountKeyPath": "./service-account-file.json",
"track": "production"
}
}
}
}
我们还可以使用与内部测试版本相同的 EAS 构建。运行 eas submit
命令以发布到 Play 商店:
¥We can also use the same EAS Build we did for the internal testing release. Run the eas submit
command to release to the Play Store:
-
eas submit -platform android
要创建轨道并将我们的应用提交给 Google Play 商店的审核流程,我们需要“发布”>“生产”,然后在“发布”下选择我们要发送以供审核的版本。
¥To create a track and submit our app to the Google Play Store's review process, we need to Release > Production and under Releases, select the build we want to send for review.
9
¥Automated release
对于未来的后续版本,我们可以通过使用 --auto-submit
标志和 eas build
将构建创建和 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
:
-
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.