Android Play 商店部署
如果你使用的是 Capacitor,你还可以参考 Capacitor 文档中的 部署到 Google Play。
🌐 If you are using Capacitor, you can additionally refer to the Capacitor documentation for Deploying to Google Play.
生成应用的发布版本
🌐 Generating a release build of an app
- Capacitor
- Cordova
要为 Android 生成发布版,请先构建你的 Web 应用,然后运行以下 CLI 命令:
npx cap copy && npx cap sync
这将复制所有网络资源并同步所有插件更改。
🌐 This will copy all web assets and sync any plugin changes.
接下来,打开 Android studio:
🌐 Next, open Android studio:
npx cap open android
要为 Android 生成发布版本,请运行以下命令行指令:
ionic cordova build android --prod --release
这将根据应用 platforms/android/app/build/outputs/apk 目录下的 config.xml 中的设置生成一个发布版本构建。Ionic 应用在此文件中会有预设的默认值,但可以更改这些值以自定义构建。
🌐 This will generate a release build based on the settings in the config.xml in the platforms/android/app/build/outputs/apk directory of an app.
An Ionic app will have preset default values in this file but this can be changed to customize builds.
签署 APK
🌐 Signing an APK
- Capacitor
- Cordova
使用 Android Studio 在本地创建 AAB 二进制文件:
- 打开构建菜单
- 选择 生成已签名的 Bundle / APK
- 按照提示使用你的密钥库文件签署 AAB
有关完整详情,请查看 Android 文档。
🌐 For complete details, view the Android documentation.
Google Play 签名
🌐 Google Play Signing
如果你尚未切换到 Android 应用包,则需要在 Google Play 控制台中选择加入 Play 应用签名才能发布它们。
🌐 If you haven't made the switch to Android app bundles yet, you will need to opt into Play App Signing in the Google Play Console to be able to publish them.
新应用
🌐 New Apps
首先,在 Google Play 控制台中创建一个新应用。为了启用应用签名,你需要导航到新版本页面,可以在正式发布、开放测 试、封闭测试或内部测试页面之一找到。 选择下方所示的“创建新版本”按钮(发布类型无关紧要,因为你现在不需要真正创建一个新版本):
🌐 First, create a new app in the Google Play Console. In order to enable app signing, you'll need to navigate to the new release screen, on one of the Production, Open testing, closed testing, or internal testing pages. Select the Create new release button as seen below (it doesn't matter which release type, since you don't have to actually go through with creating a new release right now):

在应用完整性部分,点击 更改应用签名密钥 按钮:
🌐 Under the App integrity section, click the Change app signing key button:

接下来,选择 从 Java 密钥库导出并上传密钥 选项。这是保留密钥并让 Google Play 使用它进行签名的唯一方式。如果你使用 Appflow 在云端构建 Android 应用,这也是必选的选项,以便将密钥库文件上传到 Appflow。
🌐 Next, select the Export and upload a key from Java Keystore option. This is the only way in which you can retain the key and have Google Play use it for signing. If you're using Appflow to build Android apps in the cloud, this is also the required option so you can upload the keystore file to Appflow.

按照屏幕上的说明生成 Keystore,你也可以在 Appflow 仪表板中使用相同的 Keystore 文件为你的应用签名。如果你在生成 Keystore 文件时需要任何帮助,可以参考我们的文档 这里。
一旦生成的压缩文件上传完成,你就准备好了!使用该 Keystore 文件签名构建 AAB 二进制文件,然后将其上传到 Google Play。
🌐 Follow the instructions on the screen to generate the Keystore and you can use the same Keystore file to sign your app in the Appflow dashboard as well. If you need any help generating the Keystore file, you can refer to our docs here. Once the generated zip file has been uploaded, you're all set! Build an AAB binary signed with the keystore file then upload it to Google Play.
现有应用
🌐 Existing Apps
截至目前,现有应用不需要使用 AAB 格式,但你仍然可以使用 Play 应用签名来注册它们。
🌐 As of now, existing apps aren't required to use the AAB format, but you can still enroll them using Play App signing.
要选择加入应用签名,你需要上传用于签署应用先前版本的应用签名密钥。导航到设置 -> 应用完整性, 然后选择下图中看到的两种方法之一。上传密钥后,你即可注册 Play 应用签名。
🌐 To opt into app signing, you'll need to upload the app signing key used to sign previous releases of the app. Navigate to Setup -> App integrity, then choose one of the two methods seen in the screenshot below. Once the key has been uploaded, you can enroll in Play App Signing.

由于应用体积更小、性能提升以及安全性增强,AAB 二进制格式对应用开发者和用户来说都是一种胜利。如果你已有使用 APK 格式的 Android 应用,考虑迁移到 AAB,以利用它提供的所有优良功能。
首先,未签名的 APK 必须进行签名。如果已经生成了签名密钥,则跳过这些步骤,直接使用该密钥即可。 使用随 Android SDK 提供的 keytool 命令生成一个私钥:
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
一旦该命令被运行并且其提示被回答后,当前目录中将会创建一个名为 my-release-key.keystore 的文件。
🌐 Once that command has been ran and its prompts have been answered a file called my-release-key.keystore will be created in the current directory.
保存此文件并将其放在安全的地方。如果丢失,Google Play 商店将不接受此应用的更新!
要对未签名的 APK 进行签名,请运行 Android SDK 中包含的 jarsigner 工具:
🌐 To sign the unsigned APK, run the jarsigner tool which is also included in the Android SDK:
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore HelloWorld-release-unsigned.apk alias_name
最后,必须运行 zip 对齐工具以优化 APK。
可以在 /path/to/Android/sdk/build-tools/VERSION/zipalign 中找到 zipalign 工具。
例如,在安装了 Android Studio 的 macOS 上,zipalign 位于 ~/Library/Android/sdk/build-tools/VERSION/zipalign:
🌐 Finally, the zip align tool must be ran to optimize the APK.
The zipalign tool can be found in /path/to/Android/sdk/build-tools/VERSION/zipalign.
For example, on macOS with Android Studio installed, zipalign is in ~/Library/Android/sdk/build-tools/VERSION/zipalign:
zipalign -v 4 HelloWorld-release-unsigned.apk HelloWorld.apk
这会生成一个名为 HelloWorld.apk 的最终版本二进制文件,可以被 Google Play 商店接受。
🌐 This generates a final release binary called HelloWorld.apk that can be accepted into the Google Play Store.
将应用提交到 Google Play 商店
🌐 Submitting an app to the Google Play Store
现在已经生成了发布 AAB/APK,可以编写 Play 商店列表并上传 AAB/APK。
🌐 Now that a release AAB/APK has been generated, a Play Store listing can be written and the AAB/APK can be uploaded.
首先,访问 Google Play 商店开发者控制台 并创建一个新的开发者账户。
🌐 To start, visit the Google Play Store Developer Console and create a new developer account.
在 Google Play 上创建开发者账户的费用为 25 美元。
一旦开发者账号创建完成,继续点击 Create an Application
🌐 Once a developer account has been created, go ahead and click the Create an Application

请务必填写应用的描述,同时提供截图和其他信息。准备好后,上传生成的已签名发布 AAB/APK 并发布应用。
🌐 Be sure to fill out the description for the app along with providing screenshots and additional info. When ready, upload the signed release AAB/APK that was generated and publish the app.
更新应用
🌐 Updating an app
随着应用的发展,它需要通过添加新功能和修复来进行更新。应用可以通过提交新版本到 Google Play 商店,或者使用像 Appflow 的实时更新功能这样的 实时更新服务来进行更新。使用实时更新,可以直接从 Appflow 仪表板向用户推送更改,而无需向 Play 商店提交更改。了解有关实时更新的更多信息 这里。
- Capacitor
- Cordova
为了让 Google Play 商店接受更新的 AAB/APK,需要编辑 android/app/build.gradle 文件以增加 versionCode 值,然后按照上述说明重新构建应用以发布。
为了让 Google Play 商店接受更新的 AAB/APK,需要编辑 config.xml 文件以增加版本值,然后按照上述说明重建应用以进行发布。