Emad Pourahmadi

Android Developer

Freelancer

Java/Kotlin

Gamer

Emad Pourahmadi

Android Developer

Freelancer

Java/Kotlin

Gamer

Blog Post

Building your first app bundle

2021/02/04 Android Development

With the Android App Bundle we created a format that unlocks, amongst other things, shipping smaller apps to your users. Smaller apps are more likely to be installed and less likely to be uninstalled when disk space gets tight.

In this post we’ll take a closer look at how to build your first app bundle, how you can upload it using the Play Console and dive into some configuration options.

Getting started doesn’t require any changes to your existing codebase.

All you’ll need to do is create an Android App Bundle, using the command line or Android Studio.

Building on the command line

On the command line, you’ll run one of the bundle tasks like this:

./gradlew bundleRelease

Then locate the bundle in your application’s build directory. The default location is app/build/outputs/bundle/release.

This bundle needs to be signed. When using jarsigner, this is how you sign the bundle:

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

Once the variables are replaced with actual values and the keystore password is entered, the bundle will be signed and ready for upload.

Building in Android Studio

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

Whether you use the command line or Android Studio, the process will leave you with a built and signed release bundle that’s ready for upload to the Play Store.

Uploading through the Play Console

To upload your app bundle to the Play Store, create a new release on a chosen release track. You can drag and drop the bundle into the “App bundles and APKs” section or use the Google Play Developer API.

Image for post
Highlighted (green) section of Play Console for upload of App Bundles.

Once the Bundle is uploaded, the Play Store can optimize the APKs it delivers to users’ devices based on their configuration. This in turn reduces download and installation size.

Exploring your Android App Bundle

To take a look at how the Play Store ships your app to a user’s device, you can click on the “Details” button at the end of the bundle’s row.

Image for post
Screenshot of the highlighted “Details” button

In the details screen you already see a lot of information on your app bundle such as version code, minSdk level, target SDK, required features, permissions, screen layouts, localizations and much more.

And you also can download signed APKs for your app, to see exactly what the Play Store delivers to a specific device. To navigate there, click on “Explore Bundle” and then open the “Downloads” tab.

You can either select a specific device or apply one or more of the many filters from the “Add filter” tab.

Image for post
Opened filter tab in the app bundle explorer

Download the app bundle and install locally

In the app bundle explorer, at the end of your screen, there is a “Download” button which provides a zip file, containing several APK, which are tailored to the specific device in question.

After you download and unzip the file, the containing APK can be installed on a local emulator or device by using `adb install — multiple *.apk` from the containing directory.

While each apk in this set is relevant to guarantee correct execution of your app, I want to point out that the base.apk always has to be installed on a device in order to provide your app’s core functionality. Next to code and resources the base module also contains the merged AndroidManifest and shared dependencies for the entire application.

Each feature module or configuration split provides its own resources and can contain code, but the base module is what ties it all together.

Disabling optimizations

You can disable the optimization in each module’s build.gradle file. All you have to do is edit the languagedensity or abi property and set enableSplit to false. This will tell the build system that it should not optimize this specific dimension.

Unless you have a good reason to, I recommend not touching this section as setting enableSplit to false can dramatically increase the on-device installation size of your app.

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

There could be exceptions, such as when your app has its own language selector built in and you want to have all potential languages available for selection at all times. But even then, using the Android App Bundle provides you with ways to load features on demand instead. This could be used to avoid to pre-install parts of your app that only a subset of users might need.

Happy bundling!