[Huawei Developers] John Wo:
Overview

Android App Bundle (.aab) is a new publishing format introduced by Android. A few out of many benefits of using app bundle are dynamic ability, automatic multi-APK distribution, smaller APK size and dynamic feature modules.

AppGallery uses your app bundle to generate and serve optimized APKs for each user’s device configuration, so they download only the code and resources they need to run your app. For example, a user should not get x86 libs if the device architecture is armeabi. Also, users should not get other resources like strings and drawables they are not using.

Introduction

Dynamic Ability modules allow you to separate certain features and resources from the base module of your app.

HUAWEI AppGallery provides a sub-app bundle that adapts only to the user's device type, thereby reducing network data and device storage space, with which the same service functions can be provided.

Dynamic Ability initial app download is smaller for all users. Developers can customize how and when that feature is downloaded onto devices running Android 5.0 (API level 21) or higher. It gives freedom to integrate large 3rd party libraries (< 150MB) on demand.

Dynamic Ability with split APKs

Split APKs are very similar to regular APKs. They can 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. The benefit of split APKs is to break up a monolithic APK into smaller, discrete packages that are installed on a user’s device as required.

Base APK: This APK contains code and resources that all other split APKs can access and provides the basic functionality for your app.

Configuration APKs: Each of these APKs includes native libraries and resources for a specific screen density, CPU architecture, or language. That is, they are downloaded and installed along with the APK they provide code and resources for.

Dynamic Feature APKs: Each of these APKs contains code and resources for a feature of your app that is not required when your app is first installed. That is, using the Dynamic ability SDK, dynamic APKs may be installed on-demand after the base APK is installed on the device to provide additional functionality to the user.

Prerequisite

1. A computer with Android Studio installed and able to access the Internet

2. Huawei phone

3. Java JDK (1.8 or later)

4. Android API (level 21 or higher)

5. Android Studio (3.2 or later)

Integration process

1. Open the build.gradle file in the root directory of your Android Studio project.

dependencies {
implementation 'com.huawei.hms:dynamicability:1.0.11.302' ...
}

2. Add the following lines in the build.gradle file in Base App. In the file, the Android closure contains the following configuration.

android {

// Ignore irrelevant configurations.

// Base App is associated with Dynamic Feature Module.
dynamicFeatures = [":demofeature"]
}

3. Add the following lines in the build.gradle file in Dynamic Feature Module. In the file, the dependencies closure contains the following configuration.

dependencies {
// Ignore irrelevant configurations.

// The module depends on Base App.
implementation project(':app')
}

3. Add the following lines in the build.gradle file in Dynamic Feature Module. In the file, the dependencies closure contains the following configuration.

dependencies {
// Ignore irrelevant configurations.

// The module depends on Base App.
implementation project(':app')
}

4. Set Application for Base App in the project, override the attachBaseContext() method, and add the SDK startup code.

public class MyApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
// Start the Dynamic Ability SDK.
FeatureCompat.install(base);
}
}

5. Add the following configuration to the activity in the feature.

@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
FeatureCompat.install(newBase);
}

More details, you can visit https://forums.developer.huawei.com/forumPortal/en/topic/0204411536738730208