android app bundle完整指南

Google introduced new app publishing format on play console known as Android App Bundle (.aab extension) and is now the official publishing format. It was introduced in Google I/O 2018 and by second half of 2021, all new apps submitted on play console must use this format instead of Android Package(.apk extension) .

Google在播放控制台上引入了新的应用程序发布格式,称为Android App Bundle (扩展名为.aab),现已成为官方发布格式。 它是在Google I / O 2018中引入的,到2021年下半年,在游戏机控制台上提交的所有新应用都必须使用此格式而不是Android Package(.apk扩展名)。

什么是Android App Bundle? (What is Android App Bundle ?)

An Android App Bundle is a publishing format that includes all your app’s compiled code and resources, and defers APK generation and signing to Google Play.

Android应用程序捆绑包是一种发布格式,其中包括您应用程序的所有已编译代码和资源,并推迟了APK的生成和对Google Play的签名。

Google Play uses your app bundle to generate and serve optimized APKs for each device configuration, so only the code and resources that are needed for a specific device are downloaded to run your app. You no longer have to build, sign, and manage multiple APKs to optimize support for different devices, and users get smaller, more-optimized downloads.

Google Play使用您的应用捆绑包为每种设备配置生成并提供优化的APK,因此只有特定设备所需的代码和资源才能下载以运行您的应用。 您不再需要构建,签名和管理多个APK来优化对不同设备的支持,并且用户可以获得更小,更优化的下载。

It differs from APK in the manner that you can’t directly deploy it to a device and then use it. Rather, it is a publishing format that includes all your app’s compiled code and resources in a single build artifact.

它与APK的不同之处在于您无法将其直接部署到设备上然后再使用它。 相反,它是一种发布格式,在单个构建工件中包含了应用程序的所有已编译代码和资源。

Android App Bundle的优势 (Advantage of Android App Bundle)

  • Smaller app size : Google Play automatically splits the apk into multiple apk’s that are optimized for each device configuration. This means users enjoy smaller app downloads without the unused code and resources needed for other devices. On average, apps published with app bundles are 20% smaller in size.

    较小的应用程序尺寸: Google Play会自动将APK拆分为针对每种设备配置进行了优化的多个APK。 这意味着用户可以享受较小的应用程序下载,而无需使用其他设备不需要的代码和资源。 平均而言,通过应用捆绑发布的应用的大小要小20%。

  • Customize features Delivery : This feature allows you to make the users firstly download and install the app. Then, you can later ask the users to download a particular feature. For example, a gaming may ask to install new levels or a camera app asking to download filters.

    自定义功能交付:使用此功能,您可以使用户首先下载并安装该应用程序。 然后,您以后可以要求用户下载特定功能。 例如,游戏可能要求安装新关卡,或者相机应用程序要求下载滤镜。

  • Relief from managing multiple APK’s : Previously, to build optimized apps, developers need to manage multiple apks of the same app with different version codes but same package name. It was hard and time-consuming to handle such situation (especially if you are a beginner or intermediate in Android). But, by using android app bundles this all is managed by Google Play and you need not to worry about it.

    减轻管理多个APK的负担以前,要构建优化的应用程序,开发人员需要使用不同的版本代码和相同的包名称来管理同一应用程序的多个apk。 处理这种情况非常困难且耗时(特别是如果您是Android的初学者或中级)。 但是,通过使用android应用程序捆绑包,这一切都由Google Play管理,您无需担心。

It also has other advantages like efficient app releases, faster build times and it also offer Google Play Instant experiences.

它还具有其他优势,例如高效的应用发布,更快的构建时间,还提供了Google Play Instant体验

建立Android应用程式套件 (Building an Android App Bundle)

This feature is available in Android Studio 3.2 or later, Unity 2018.3 & 2017.4.17, and Cocos Creator 2.0.9 or later.

此功能在Android Studio 3.2或更高版本,Unity 2018.3&2017.4.17和Cocos Creator 2.0.9或更高版本中可用。

  • Firstly, include the following code in your build.gradle(Module:app) in android{} block.

    首先,在android {}块的build.gradle(Module:app)中包含以下代码

bundle {
language {
enableSplit = true
}
density {
enableSplit = true
}
abi {
enableSplit = true
}
}
  • Then, go to Build > Build Bundle(s)/APK(s) and select Build Bundle(s).

    然后,转到Build > Build Bundle(s)/APK(s)然后选择Build Bundle(s)

Image for post

This will generate a app-debug.aab file. (Android app bundle uses .aab extension).

这将生成一个app-debug.aab文件。 (Android应用程序捆绑包使用.aab扩展名)。

不同类型的拆分apk: (Different types of Split apks :)

A fundamental component of serving optimized applications is the split APK mechanism available on Android 5.0 (API level 21) and higher. Split APKs are very similar to regular APKs — they include compiled DEX bytecode, resources, and an Android manifest. However, the Android platform is able to treat multiple installed split APKs as a single app.

服务优化应用程序的基本组成部分是Android 5.0(API级别21)及更高版本上可用的拆分APK机制。 拆分的APK与常规的APK非常相似,它们包含已编译的DEX字节码,资源和Android清单。 但是,Android平台能够将多个已安装的拆分APK视为一个应用。

  • Base APK : This APK contains code and resources that all other split APKs can access and provides the basic functionality for your app. When a user requests to download your app, this APK is downloaded and installed first.

    基本APK:此APK包含所有其他拆分的APK可以访问的代码和资源,并为您的应用提供基本功能。 当用户请求下载您的应用程序时,会先下载并安装此APK。

  • Configuration APKs: Each of these APKs includes native libraries and resources for a specific screen density, CPU architecture, or language. When a user downloads your app, their device downloads and installs only the configuration APKs that target their device. Each configuration APK is a dependency of either a base APK or feature module APK. That is, they are downloaded and installed along with the APK they provide code and resources for.

    配置APK:每个APK均包含用于特定屏幕密度,CPU体系结构或语言的本机库和资源。 当用户下载您的应用时,他们的设备只会下载并安装针对他们设备的配置APK。 每个配置APK都是基本APK或功能模块APK的依赖项。 也就是说,它们与提供代码和资源的APK一起下载并安装。

  • Feature module APKs: Each of these APKs contains code and resources for a feature of your app that you modularize using feature modules. You can then customize how and when that feature is downloaded onto a device.

    功能模块APK:每个APK都包含您使用功能模块进行模块化的应用功能的代码和资源。 然后,您可以自定义如何以及何时将该功能下载到设备上。

Image for post
Dependency tree for an app served using split APKs (image credit : developer.android.com)
使用拆分APK投放的应用的依赖树(图片来源:developer.android.com)

Important: For devices running Android 4.4 (API level 20) and lower, Google Play automatically serves a single APK that’s optimized for the device’s configuration.

重要提示:对于运行Android 4.4(API级别20)及更低版本的设备,Google Play会自动提供针对设备配置进行了优化的单个APK。

使用Google Play控制台测试应用(内部测试跟踪): (Testing the app with Google Play Console (Internal Test Track) :)

Uploading an app on Play Console requires sigining of apk. So, for that, follow the steps given below :

在Play控制台上上传应用程序需要apk开头。 因此,为此,请按照以下步骤操作:

  • Select Build > Generate Signed Bundle/APK from the menu bar. In the Generate Signed Bundle or APK dialog, select Android App Bundle and click Next.

    从菜单栏中选择“ 构建”>“生成签名包/ APK ”。 在“ 生成签名包或APK”对话框中,选择“ Android应用包” ,然后单击“ 下一步”

  • In the Module dropdown menu, select the base module of the app you want to generate an app bundle for.

    在“ 模块”下拉菜单中,选择要为其生成应用程序捆绑包的应用程序的基本模块。

  • Provide information for an existing key and keystore, or create a new one. This is the same type of key and keystore information you provide when building a signed APK.

    提供有关现有密钥和密钥库的信息,或创建一个新的密钥和密钥库。 这与您在构建签名的APK时提供的密钥和密钥库信息的类型相同。

  • If you want Android Studio to also save your signing key as an encrypted file, check the box next to Export encrypted key. To be able to upload your app bundle and take advantage of Dynamic Delivery, you need to upload this encrypted file to the Play Console and enroll in app signing by Google Play.

    如果您希望Android Studio也将签名密钥另存为加密文件,请选中导出加密密钥旁边的框。 为了能够上传您的应用程序包并利用动态交付功能,您需要将此加密文件上传到Play控制台, 并通过Google Play进行应用程序签名注册。

  • Click Next and provide a Destination Folder for your app bundle. Select the Build Type and flavors that you want to generate app bundles for.

    单击下一步,然后为您的应用程序捆绑包提供目标文件夹 。 选择您要为其生成应用程序捆绑包的构建类型风味

  • Click Finish.

    点击完成

Now , we can upload this app bundle on play console. To upload on Play Console (Internal Test Track) follow this tutorial.

现在,我们可以将此应用程序捆绑包上传到游戏机上。 要在Play控制台(内部测试跟踪)上上传,请遵循本教程

使用bundletool测试应用程序包: (Testing app bundle using bundletool :)

To generate an APK set for all device configurations your app supports from your app bundle, use the bundletool build-apks command

要为您的应用程序捆绑包中的应用程序支持的所有设备配置生成APK集,请使用bundletool build-apks命令

$ bundletool build-apks --bundle=<path to .aab> --output=<out.apks>

Only two arguments are required,

只需要两个参数,

  • The path to the .aab file and,

    .aab文件的路径,以及
  • The directory where the generated apks are stored.

    生成的apk的存储目录。

Now you can run build-apks.

现在,您可以运行build-apks。

WARNING: The APKs won't be signed and thus not installable unless you also pass a keystore via the flag --ks.$ bundletool build-apks --bundle=/MyApp/my_app.aab --    output=/MyApp/my_app.apks
--ks=/MyApp/keystore.jks
--ks-pass=file:/MyApp/keystore.pwd
--ks-key-alias=MyKeyAlias
--key-pass=file:/MyApp/key.pwd

To deploy your app from an APK set, use the install-apks command and specify the path of the APK set

要从APK集部署应用,请使用install-apks命令并指定APK集的路径

bundletool install-apks --apks=/MyApp/my_app.apks

I hope this article will help you to get through Android App Bundles.

希望本文能帮助您熟悉Android应用程序捆绑包

翻译自: https://medium.com/@mrudultora/android-app-bundle-complete-guide-69984d02f744

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值