A Practical Guide to Android App Bundle for Beginners
By: Bapusaheb Patil
Tags: Development, Java, Android, Programming, Mobile

Building Your First Android App Bundle

Step 1

Modify your app ’s build.gradle file.

Step 2

To build the feature1 module, go to File > New > New Module in Android Studio.

From there, select the Dynamic Feature Module that shows up in the dialog box, and click Next. From there:

Select the app module as the Base application module.

module as the Base application module. Specify feature1 as the Module name.

as the Module name. Specify a package name and a Minimum API Level for the feature1 module, and then click Next.

In the Configure On-Demand Options section:

Specify the Module title as “Feature 1”.

Check the boxes for Enable on-demand and Fusing.

Then, click on Finish.

Step 2

Your feature1 ’s manifest file should have the following contents, after you’ve added an activity to it:

And the build.gradle file for feature1 should have this in the first line, as it’s a dynamic feature:

apply plugin: 'com.android.dynamic-feature'

Repeat the above steps for feature2 .

Step 3

Let’s go back to your app ’s build.gradle file and check if the dynamic features are specified as follows:

Step 4

Now, go to your feature1 and feature2 ’s build.gradle files and check if your app module is added as a dependency.

Step 5

Let’s write the code in the app module for downloading the feature1 module when required.

Add the following dependency to your app ’s build.gradle file:

implementation 'com.google.android.play:core:1.3.4'

In the activity/fragment where you want the dynamic feature to load on-demand, write the following code:

Again, repeat the same for feature2 as well, wherever it’s needed.

Step 6

Under the hood, Android Studio, Gradle, and Google Play use a tool called the bundletool to build your App Bundle, which is also available as a command-line tool.

To build a debug version of your App Bundle:

Click on Build > Build Bundle(s)/APK(s) > Build Bundle(s), or you can do it in the command line as follows:

./gradlew :base:bundleDebug

Step 6: Debug version of the Android App Bundle

The bundle can be found at: project-name/app/build/outputs/bundle/ .

To build a signed release version of your App Bundle to upload to your Google Play Console:

Click on Build > Generate Signed Bundle/APK, then select Android App Bundle and click Next. Then, select the app module from the Module dropdown, which is your base module for which the App Bundle is built. Type in the details of your key after selecting your keystore, just as you normally would to sign an APK. In this step, I’d recommend checking the Export encrypted key checkbox. You’ll need to upload this encrypted key file to the Google Play Console later. Click Next when you’re done here. Select your Destination Folder and select the release in Build Types and all the flavors in Flavors you want to build your App Bundle for, and then click Finish.

Step 6: Release version of the Android App Bundle

Uploading to the Google Play Console:

Once you’re granted access, you can publish your Android App Bundle to production!

And that’s it. You’re done with your first Android App Bundle!