Dynamic Feature Module with Product Flavors and App Bundle
Recently Google came out with a new app serving model: “Dynamic Feature Module”. The Overall concept is way-out like one has only to download data which he is using. I took this as a challenge and tried to implement in one of the largest sustainable projects of my obligation similar to PayTM which was quite intricate with 11 modules and 500+ MB size...
There are too many blogs respecting how to enforce the dynamic module, app bundle, flavors in android but, this article is helpful for those who are in search of dynamic feature module with product flavors as there is relatively less information regarding this over the internet.
Assume there are two modules for example “App module” and “dynamic module”.
Dynamic module build.gradle
App Module AndroidManifest.xml
Dynamic Module AndroidManifest.xml
Dynamic Module Download Method
Important stuff to keep in mind:
- Eliminate multidex from app module.
- Eliminate data binding v2 from gradle.properties.
- Make sure you have implemented jcenter(), google() in all projects repositories in project app module gradle file.
- You need to override a method in application class as below…
- override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
SplitCompat.install(this)
}
5. In case you found any error as below.
- What went wrong:
Execution failed for task ‘:app:packageProdReleaseBundle’.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Modules ‘base’ and ‘apphub’ contain entry ‘res/drawable-v24/$ic_launcher_foreground__0.xml’ with different content. - It is because of repeated named resources…. refactor it and it will work.
These are some central highlighted issues I have gone through and overcame. This is a quite handy and simple explanation for dynamic feature with product flavors…
App Bundle is a wide concept. You no longer have to build, sign, and manage multiple APKs to support different devices, and users get smaller, more optimized downloads.
If you have any kind of issues, problems regarding app bundle, dynamic feature modules, product flavors, please ask it in the comment section.
Also check out: Implementation of .aar in a large project.
If you are seeing this…please clap…it won’t take hard on your palm…Thank you so much. It’s time to say “Good-Bye”…