2

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 ?

Lucifer
  • 29,392
  • 25
  • 90
  • 143
  • I know it may not be related , But I'm facing the same problem and it's literally driving me crazy. I did everything testing it from play store and every single step the documentation requires. I've posted my question on SO with no answers till now https://stackoverflow.com/questions/66173144/android-dynamic-feature-error-2-module-unavailable , it has a bounty please may you have a look – Badran Feb 16 '21 at 21:49
  • I am facing an issue: When I install the app the first time, it did not get the feature module activity and it gives me a class not found, app crash. After the second time when I open the app, it works as expected. Please help. – Shivang Feb 26 '21 at 10:36
  • @Shivang, try this way, https://stackoverflow.com/a/66253980/996493 – Lucifer Feb 27 '21 at 04:05

1 Answers1

3

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.

Sonia
  • 508
  • 4
  • 11
  • I am facing an issue: When I install the app the first time, it did not get the feature module activity and it gives me a class not found, app crash. After the second time when I open the app, it works as expected. Please help. – Shivang Feb 26 '21 at 10:36
  • According to [this](https://developer.android.com/guide/app-bundle/test/testing-fakesplitinstallmanager#build-apks) "The `--local-testing` flag includes meta-data in your APKs' manifests that lets the Play Core library know to use the local split APKs to test installing feature modules, without connecting to the Play Store." – Ivan Mar 23 '21 at 16:17
  • I am facing issues with `install-time` modules. Check my unanswered question here https://stackoverflow.com/questions/70868932/install-time-feature-module-working-as-on-demand-feature-module. – Aayush Goyal Mar 26 '22 at 10:15