Dynamic Feature Module with Hilt

Dynamic Feature Module with Hilt

 
 
 
 
 
Hilt_DFM
yamasaUpdated Nov 19, 2025
Dynamic-Feature-MultiModule
alirezaeiiiUpdated Aug 13, 2025
 
 
Here’s the clear explanation of how Dynamic Feature Modules actually work and why you’re seeing a single APK in release builds:

Why your Dynamic Feature Module looks like it is “embedded” in the APK

In debug builds and standard release builds (APK), Android Studio packs all modules—including dynamic features—into ONE APK unless you explicitly build an App Bundle (.aab).
So yes — the reason your release APK contains everything is:

👉 Dynamic Feature Modules work ONLY with App Bundles (.aab), NOT with standalone APKs.

When you create:
  • APK (app-release.apk) → Everything is merged into one file → dynamic module looks “embedded”
  • App Bundle (app-release.aab) → Dynamic features become truly dynamic (separate, on-demand installable)

🧩 So what actually makes a module “dynamic”?

A module becomes dynamic when:

1. You apply this plugin:

plugins { id("com.android.dynamic-feature") }

2. You add it to base module:

dynamicFeatures = [":feature_player"]

3. You build an App Bundle:

Build > Build Bundle(s) / APK(s) > Build Bundle(s)

4. Play Store or Play Core delivers the feature module on demand, for example:

splitInstallManager.startInstall( SplitInstallRequest.newBuilder() .addModule("feature_player") .build() )

🔥 IMPORTANT → APK vs AAB Behavior

When building APK

✔ Dynamic module included
✔ No on-demand downloading
✔ No modular delivery
❌ Dynamic behavior doesn’t exist
❌ Play Core API won’t download anything because everything is already inside

When building AAB

✔ Base APK + separate module APKs
✔ Feature is NOT downloaded unless requested
✔ App size reduces on store
✔ You get true dynamic delivery

⭐ TL;DR

Build Type
Dynamic Modules?
Result
Debug APK
❌ Not dynamic
All modules merged
Release APK
❌ Not dynamic
All modules merged
Release AAB
✅ Truly dynamic
Modules delivered on-demand

✔ Your confusion resolved

You're currently building APK, so:
➡️ It becomes single merged APK
➡️ Your dynamic module behaves like a normal module
➡️ It is embedded inside the APK
To see true dynamic behavior, you MUST:

→ Build an App Bundle (.aab)

→ Upload to Play Store or test with bundletool


If you want, I can show you:
✅ How to generate an AAB locally
✅ How to test dynamic feature download without Play Store
✅ How to structure your modules properly
Just tell me!

You said:

✅ How to test dynamic feature download without Play Store

ChatGPT said:

Here is the correct and complete way to test Dynamic Feature Module downloading locallywithout Play Store.
This uses bundletool to simulate Play Store delivery on your device.

Step-by-Step: Test Dynamic Feature Module locally

STEP 1 — Build an App Bundle (.aab)

In Android Studio:
Build > Build Bundle(s) / APK(s) > Build Bundle(s)
Output file example:
app-release.aab

STEP 2 — Install bundletool

Download from Google:
Save it as:
bundletool.jar

STEP 3 — Generate a local “fake Play Store” set of APKs

Run this command:
java -jar bundletool.jar build-apks \ --bundle=app-release.aab \ --output=app.apks \ --mode=universal
Or, to generate split APKs (recommended):
java -jar bundletool.jar build-apks \ --bundle=app-release.aab \ --output=app.apks \ --connected-device
This creates a ZIP file (app.apks) containing:
  • Base apk
  • Feature module apk(s)
  • Config apks

STEP 4 — Install it as Play Store would do

java -jar bundletool.jar install-apks --apks=app.apks
This installs only the base module to the device.
Dynamic feature modules will NOT be installed until requested via Play Core API.

STEP 5 — Trigger your dynamic module download from the app

Use this code in your app:
val manager = SplitInstallManagerFactory.create(context) val request = SplitInstallRequest.newBuilder() .addModule("feature_player") // your module name .build() manager.startInstall(request) .addOnSuccessListener { Log.d("DFM", "Module download started") }.addOnFailureListener { Log.e("DFM", "Install failed: $it") }

🎉 STEP 6 — Watch the feature module download LIVE

In Logcat, you will see:
Downloading module: feature_player Install success
On device:
  • Feature is delivered as a separate APK
  • Your Activity/Fragment from that module now becomes available
  • App size increases dynamically

⭐ OPTIONAL — Verify installed modules

adb shell pm list packages -f
You will see separate installed APKs:
.../split_feature_player.apk=your.package.name

🧪 BONUS — Force uninstall dynamic module to test again

adb shell pm uninstall your.package.name
Then re-install using bundletool again.

✔ TL;DR (Fast Summary)

What you do
Purpose
Build AAB
Required for dynamic delivery
Use bundletool to generate .apks
Simulates Play Store
Install via bundletool
Installs base only
Trigger Play Core install
Downloads feature on demand