Build your first app bundle | mad skills

Time:2021-5-13

This is a new series of articles, which we call “modern Android development skills” or “mad skills” for short. This series of articles is dedicated to helping developers create a better modern Android development experience. Please pay attention.

Today, I’d like to release the fifth article in this series: build your first app bundle. If you want to review the content published in the past, please refer to the following link:

Among other features, the android app bundle format we created unlocks the ability to publish smaller applications. The smaller the application sizeIt means that it is more likely to be downloaded, and it also means that it can avoid being unloaded more when the disk space is insufficient.In addition, in the second half of 2021, Google play will requireNew apps and games are released in the android app bundle format

In this article, we will describe in detail how to build your first app bundle, how to upload app bundles through play console, and how to understand some configuration options.

There is no need to change the existing code base to use app bundle.

You only need to use the command line or Android studio to build an android app bundle.

Build from the command line

If you use the command line, you need to run one of the bundle tasks as follows:

./gradlew bundleRelease

Then find the bundle file in the build folder of your application. The default path is app / build / outputs / bundle / release.

This bundle file needs to be signed first. If you use jarsigner, you need to sign the bundle file as follows:

jarsigner -keystore $pathToKeystore app-release.aab $keyAlias

Please use the configuration of your actual project to replace the parameters of the above command. After entering the keystore password, the bundle file will be signed, and then it can be uploaded at any time.

Build through Android studio

In Android studio, select “build = > generate signed bundle / APK” and follow the dialog prompts to complete the build.

Whether you use the command line or Android studio, the whole process will help you generate a signed distribution bundle that can be uploaded to the play store.

Upload via play console

In order to upload an app bundle to the play store, you first need to select a distribution channel to create a new one. You can drag and drop the bundle file to the “app bundles and apks” section, or use theGoogle play developer APIUpload.

Build your first app bundle | mad skills

The highlighted (green) part of play console is prepared for uploading app bundles

After the bundle file is uploaded, the play store will optimize the APK file according to the user’s device configuration. At the same time, this step will also reduce the size of download and installation.

Explore your Android App bundle

If you want to see how the play store distributes your app to user devices, you can click the “details” button at the end of the bundle line.

高亮的 "Details" 按钮截图

Screenshot of highlighted details button

In the details page, you can see a lot of information about the application bundle, including version number, minsdk version, target SDK, function dependency, permissions, screen size, localization and other related information.

You can also directly download the APK file signed by the app to view the specific content distributed to specific devices by the play store. You can access this page by clicking “explore bundle” and opening the “downloads” tab.

In this page, you can either directly select a specific model of device, or add one or more filter conditions to match the corresponding device through the “add filter” drop-down menu.

Build your first app bundle | mad skills

Filter drop down menu opened in app bundle Explorer

Download the app bundle and install it locally

At the end of the app bundle Explorer page, there is a “download” button to download a zip compressed file, which contains multiple apks and is customized for the target device discussed above.

After downloading and decompressing this file, all the APK files contained in it can be installed to the local simulator or device by using the ADB install multiple *. APK command in the folder path.

All APK files here are related to the normal operation of the application, and I want to point out thatbase.apkIt must be installed. It provides the core functions of your application. In addition to the code and resources, the base module also contains the merged Android manifest file and the dependencies of the whole application.

Each function module or APK file with different configuration contains its corresponding resources and code, and the base module will integrate all these modules together.

Cancel optimization

You can use thebuild.gradleTo cancel the optimization, you only need to specifylanguagedensityperhapsabi, and setenableSplitbyfalseThis tells the build system that it does not need to be optimized for the specified configuration.

Unless it is necessary, I do not recommend modifying this section, because setting enablesplit to false will greatly increase the amount of space your application takes up during device installation.

//This configuration specifies how an application bundle should be based on the
//Language, screen pixel density and CPU architecture (ABI) to split APK.
//The default value is true
//This means that each different related configuration generates a decomposed APK.

bundle {
    language {
        enableSplit = true
    }
    density {
        enableSplit = true
    }
    abi {
        enableSplit = true
    }
}

Of course, there are exceptions. For example, you have built-in language options in your application, and you want all possible languages to be loaded all the time. Even so, using Android App bundle can also provide you with a way to load functional modules on demand, which can help your application avoid installing functional modules that only a small number of users may use.

In order to enable you to download and install the function module programmatically, we also provide a split API for your convenience. This API is a part of the playcore library. We will introduce it in detail in the next article in the mad skills series. Please pay attention to it.

The content of this article corresponds to the video:https://www.youtube.com/watch?v=IPLhLu0kvYw