AppGallery Connect Dynamic Ability Feature

Önder
Huawei Developers
Published in
4 min readAug 19, 2020

Hello everyone, in this blog I will explain to you what Dynamic Ability feature is and how it is used.

What Is Dynamic Ability?

Dynamic Ability is a service in which HUAWEI AppGallery implements dynamic loading based on the Android App Bundle technology. Apps integrated with the Dynamic Ability can dynamically download features or language packages from HUAWEI AppGallery on user requests. Its benefits are reducing the unnecessary consumption of network traffic and device storage space. Currently, the Dynamic Ability SDK supports mobile phones, smart screens, and speakers with screens.

How It Works?

After the newly created AAB file of an app is uploaded to HUAWEI AppGallery, the platform splits the app into multiple APKs based on three dimensions: language, screen density, and ABI architecture. When a user downloads an app, HUAWEI AppGallery delivers an APK that is suitable for the user device based on the device language, screen density, and ABI architecture. This reduces the consumption of storage space and network traffic on the user device without affecting the app’s features. When a user downloads an app for the first time, only the basic feature module of the app is downloaded, and dynamic features are downloaded only when necessary.

Development Process

First, we create an Anroid Studio project and we configure build.gradle files.

After that, we need to add Dynamic Feature Module to our project.

We create module name and package name.

We configure module download options.

And we sync the project.

This is the structure of our main project and our dynamic feature.

We override the attachBaseContext method in the project and in an activity of a dynamic feature module, and call FeatureCompat.install to initialize the Dynamic Ability SDK.

We call FeatureInstallManagerFactory.create method to instantiate FeatureInstallManager in onCreate method of our main app.

We build a request for dynamic loading, one or more dynamic features can be added. And we call the installFeature method to install features.

We register a listener to monitor the status of the feature installation request. There are three types of listeners: OnFeatureCompleteListener, OnFeatureSuccessListener, and OnFeatureFailureListener.

– OnFeatureCompleteListener: Callback is triggered no matter whether the status is successful or failed. We need to determine whether the request is successful or not. If the request fails, an exception will be thrown when FeatureTask.getResult is called.

OnFeatureSuccessListener: Callback is triggered only after HUAWEI AppGallery successfully responds to the request. The callback result contains sessionId, which is the unique ID of a dynamic loading task. With sessionId, we can obtain the dynamic loading progress and cancel a task any time.

OnFeatureFailureListener: Callback is triggered only when HUAWEI AppGallery fails to respond.

To use the Dynamic Ability, a user must agree to the agreement of HUAWEI AppGallery. Before downloading a dynamic feature, our app needs to verify that the user agrees to the agreement.

  • If the user agrees to the agreement, the installation process continues.
  • If the user rejects the agreement, the installation process is terminated.

Before downloading and installation of a dynamic feature, our app checks whether the user’s device is using a mobile network. According to that, a data consumption reminder is displayed to the user for download consent.

  • If the user consents to the download, the app starts to download the dynamic feature.
  • If the user does not consent to the download, the app terminates the download task.

We can monitor the download progress of the dynamic feature.

A created listener needs to be registered and deregistered at proper times.

We can check the installation status.

If a dynamic feature does not need to be installed instantly, we can choose delayed installation. With this, the feature can be installed when the app is running in the background. After receiving a delay request, HUAWEI AppGallery will delay the installation based on the device running status.

We can delay the uninstallation of a dynamic feature that is no longer used. The uninstallation is not executed instantly, it is executed when the app is running in the background.

Each dynamic loading task has a unique ID, which is specified by sessionId. We can cancel an ongoing task based on sessionId at any time.

We can obtain the execution status of the task.

We also can obtain the execution status of all tasks in the system.

During actual usage of an app, the user language may vary. We can dynamically load one or more language packages in our app at a time.

A language package does not need to contain the country code. For example, to load a French package, only fr needs to be entered. The Dynamic Ability SDK automatically loads French resources of multiple countries and regions. To reduce ambiguity, it is advised to use the Locale.forLanguageTag(lang) method to modify the original value of language.

With this implementation, users can download the basic feature of the app first. And when they need, they can install other necessary features and uninstall unnecessary features.

References

--

--