Recently in 2018, Google has announced new feature in Android called Dynamic Feature Module
I tried same feature from this link http://www.tellmehow.co/know-android-dynamic-delivery-module/#
In my project, I got module app which is my application and dynamic module as bigbazaar,
I am using following method to download dynamic method at runtime.
private void downloadDynamicModule() {
try {
SplitInstallManager splitInstallManager =
SplitInstallManagerFactory.create(this);
SplitInstallRequest request =
SplitInstallRequest
.newBuilder()
.addModule("bigbazaar")
.build();
SplitInstallStateUpdatedListener listener = new SplitInstallStateUpdatedListener() {
@Override
public void onStateUpdate(SplitInstallSessionState splitInstallSessionState) {
if (splitInstallSessionState.sessionId() == mySessionId) {
switch (splitInstallSessionState.status()) {
case SplitInstallSessionStatus.INSTALLED:
Toast.makeText(MainActivity.this,
"Dynamic Module downloaded", Toast.LENGTH_SHORT).show();
cmdBigBazaar.setEnabled(true);
break;
}
}
}
};
splitInstallManager.registerListener(listener);
splitInstallManager.startInstall(request)
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
switch (((SplitInstallException) e).getErrorCode()) {
case SplitInstallErrorCode.MODULE_UNAVAILABLE:
Toast.makeText(MainActivity.this, "MODULE_UNAVAILABLE", Toast.LENGTH_SHORT).show();
}
}
})
.addOnSuccessListener(new OnSuccessListener<Integer>() {
@Override
public void onSuccess(Integer sessionId) {
mySessionId = sessionId;
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
From the given link & other bolgs, I found that we can test this feature via Google Play Store and at our end using a tool called "bundletool"
I have also change my Run configuration as per suggested in example link.
I have also define following attributes in my dynamic feature module's AndroidManifest.xml file,
<dist:module
dist:onDemand="true"
dist:instant="false"
dist:title="@string/title_bigbazaar">
<dist:fusing dist:include="false" />
</dist:module>
Error Log,
06-05 10:43:55.452 17566-17566/com.dynamic I/PlayCore: UID: [11746] PID: [17566] SplitInstallListenerRegistry : registerListener
06-05 10:43:55.453 17566-17566/com.dynamic I/PlayCore: UID: [11746] PID: [17566] SplitInstallService : startInstall([dynamicmodule],[])
06-05 10:43:55.463 17566-18219/com.dynamic I/PlayCore: UID: [11746] PID: [17566] SplitInstallService : Initiate binding to the service.
06-05 10:43:55.504 17566-17566/com.dynamic I/PlayCore: UID: [11746] PID: [17566] SplitInstallService : ServiceConnectionImpl.onServiceConnected(ComponentInfo{com.android.vending/com.google.android.finsky.splitinstallservice.SplitInstallService})
06-05 10:43:55.505 17566-18219/com.dynamic I/PlayCore: UID: [11746] PID: [17566] SplitInstallService : linkToDeath
06-05 10:43:56.386 17566-17582/com.dynamic I/PlayCore: UID: [11746] PID: [17566] SplitInstallService : onError(-2)
06-05 10:43:56.387 17566-18219/com.dynamic I/PlayCore: UID: [11746] PID: [17566] SplitInstallService : Unbind from service.
06-05 10:43:56.387 17566-17566/com.dynamic D/MainActivity: Exception: com.google.android.play.core.splitinstall.SplitInstallException: Split Install Error: -2
06-05 10:43:56.387 17566-17566/com.dynamic W/System.err: com.google.android.play.core.splitinstall.SplitInstallException: Split Install Error: -2
06-05 10:43:56.387 17566-17566/com.dynamic W/System.err: at com.google.android.play.core.splitinstall.ag.e(Unknown Source)
06-05 10:43:56.387 17566-17566/com.dynamic W/System.err: at com.google.android.play.core.internal.bg.a(Unknown Source)
06-05 10:43:56.387 17566-17566/com.dynamic W/System.err: at com.google.android.play.core.internal.j.onTransact(Unknown Source)
06-05 10:43:56.387 17566-17566/com.dynamic W/System.err: at android.os.Binder.execTransact(Binder.java:453)
Question
I have tried many ways but everytime when I click on download button to download dynamic module, it is giving me error code -2 which is "MUDULE_UNAVAILABLE".
How can I solve this error ?
You can't test on-demand module delivery using bundletool. (Read the final note on this article: https://proandroiddev.com/dynamic-feature-module-android-ondemand-module-android-app-bundle-ea0d872b32d)
You should instead upload your bundle to internal app sharing (or some other testing track), share it via link to your device and then test on-demand delivery.