Dynamic Delivery is one of my favorite tools in Android development. This serving model can be used to provide optimized APKs for users who create small apps and provide downloadable functionality even after the application is installed.
Before we got started, we wrote an article on how to create your own Dynamic Features Module (DFM) using step-by-step instructions and code samples. If you are new to this concept, read this article.
For more information on dynamic delivery, please visit. Official documentation..
One of the best ways to handle navigation in Compose is Jetpack creation navigationlibrary. It provides a great way to handle the back stack, pass arguments, test, and more. The following is a simple navigation as an example of code implementation.
However, when porting the application, I missed support for one of the library’s features that affected development: the dynamic feature module. To summarize briefly
:app Modules and DFM modules are inverted, as shown below.
:app The module is unaware of the existence of the dynamic function module.
NavGraph You cannot add configurable nodes to the declaration. Also, you cannot add mode nodes to other parts of your code in the navigation library.
After some thought, I developed a simple solution to overcome this problem with additional activities and deep links. First, a new activity is created within the Dynamic Features module to configure the screen.
DynamicActivity Registered in the module
AndroidManifest.xml Add a deep link and open it.In this example, the deep link
app://com.example.dynamic Will open the activity.
To test if deep linking is working, run the following adb command:
adb shell am start -W -a android.intent.action.VIEW -d “app://com.example.dynamic”
Now, in the navigation graph, create a new action that will be called when the user interacts with Composable. This will trigger a deep link during module installation.To make the code smaller, I A simple assist class created to install DFM using Kotlin DSL.. This class provides confirmation and progress dialogs to improve the user experience.
In the above code,dynamic_featureOnce the module has been validated and feature ready (that is, the installation is complete or already installed), the activity begins via a deep link.
that’s all! You can now continue to use Dynamic Delivery features in your Compose app until official support is released.
This approach is not the best approach, but it does not specifically follow the recommendation of having a single activity and will work until official support is obtained. If you already have an application that uses DFM, we recommend that you use the workaround for a period of time rather than disabling the last-user feature.
If you want to see more real-world scenario code, this is a pull request to port the DynamicFeatureModule to work with Jetpack Navigation Compose.