This is a new series of articles called “Modern Android Development Tips, “or “MAD Skills” for short. Stay tuned for this series of articles dedicated to helping developers build better modern Android development experiences.

Today is the fifth installment in this series: Building your first App Bundle. If you would like to review past posts, please refer to the link below:

  • Overview of navigation components
  • Navigate to the dialog box
  • Use SafeArgs when navigating your application
  • Use deep links to navigate

Among other features, the Android App Bundle format we created unlocked the ability to distribute smaller apps. The smaller the application size *, the more likely it is to be downloaded, and the more likely it is to avoid being uninstalled when disk space is low. In addition, in the second half of 2021, Google Play will require new apps and games to be released as Android App Bundles.

In this article, we’ll cover how to build your first App Bundle, how to upload the App Bundle through the Play Console, and take a closer look at some of the configuration options.

Using the App Bundle does not require any changes to the existing code base.

You can simply build an Android App Bundle from the command line or Android Studio.

Build from the command line

If using the command line, you need to run one of the Bundle tasks as follows:

./gradlew bundleRelease
Copy the code

Then in your application’s build directory to find the bundle file, the default path is app/build/outputs/bundle/release.

The bundle file needs to be signed first. To use Jarsigner, you need to sign the bundle file as follows:

jarsigner -keystore $pathToKeystore app-release.aab $keyAlias
Copy the code

Replace the parameters of the command above with the configuration of your actual project. After entering the keystore password, the bundle file is signed and ready to be uploaded at any time.

Build with Android Studio

In Android Studio, select “Build => Generate Signed Bundle/APK” and follow the dialog to complete the Build.

Whether you use the command line or Android Studio, the entire process will help you generate a signed distribution bundle that can be uploaded to the Play Store.

Upload through the Play Console

To upload the app bundle to the Play Store, you first need to select a distribution channel to create a new release. You can drag and drop the bundle files into the “App Bundles and APKs” section, or upload them using the Google Play developer API.

The highlighted (green) part of the Play Console is for uploading the App Bundle

After the Bundle file is uploaded, the Play Store optimizes the APK file based on the user’s device configuration. This step will also reduce the size of the download and installation.

Explore your Android App Bundle

To see how the Play Store distributes your application to user devices, click the “Details” button at the end of the bundle line.

Screenshot of the highlighted “Details” button

In the details page, you can see a lot of information about the application bundle, including the version number, minSdk version, target SDK, feature dependencies, permissions, screen size, localization, and other relevant information.

You can also download the signed APK file of the app directly to see what the Play Store distributes to specific devices. You can access this page by clicking “Explore Bundle” and opening the “Downloads” TAB.

On this page, you can select a device of a specific model or Add one or more filter criteria to match the device through the Add Filter drop-down list.

Filter drop-down menu opened in app Bundle Explorer

Download the application bundle and install it locally

At the end of the App Bundle Explorer page there is a “Download” button to Download a Zip file containing multiple APKs tailored to the target devices discussed above.

After downloading and unpacking the file, all APK files contained in it can be installed to the local emulator or device using the adb install – multiple *. APK command in that folder path.

All of the APK files here are relevant to the proper running of your application, and I want to point out that Base.apk is a must install that provides the core functionality of your application. In addition to the code and resources, the Base module contains the combined AndroidManifest file and dependencies for the entire application.

Each function module or apK file of a different configuration contains its corresponding resources and code, and the Base module integrates all these modules together.

Cancel the optimization

You can de-optimize in build.gradle for each module by specifying language, density, or ABI and setting enableSplit to false, which tells the build system that it does not need to optimize for the specified configuration.

I don’t recommend changing this section unless you have to, because setting enableSplit to false greatly increases the amount of space your application takes up on device installation.

// This configuration specifies how an application bundle should split apK based on // language, screen pixel density, and CPU architecture (ABI). // The default value is true // which means that each different related configuration generates a shred APK. bundle { language { enableSplit = true } density { enableSplit = true } abi { enableSplit = true } }Copy the code

There are exceptions, of course, if you have language options built into your application and you want all possible languages to be loaded at all times. Even so, using the Android App Bundle gives you a way to load feature modules on demand, which helps your App avoid installing feature modules that only a small percentage of users might use.

To enable you to programmatically download and install functional modules, we also provide a split API for your convenience. This API is part of the PlayCore library and will be covered in detail in the next MAD Skills article, so stay tuned.

This article is related to the video: www.youtube.com/watch?v=IPL…