Using Internal App Sharing to test on demand dynamic feature module not working
Asked Answered
I

1

6

I am trying to use internal app sharing to test that I can correctly request and download an on-demand dynamic feature module.

When I try this I can see that it first starts to download new feature correctly, but it never installs. I see these com.example is installed but certificate mismatch logs. Could that be causing the problem? I know that internal app sharing uploads are "automatically re-signed with an Internal App Sharing key, which is automatically created for your app by Google." source. Is it possible that internal app sharing is not correctly signing the on-demand apk?

Download code in question:

private const val ONDEMAND_FEATURE_MODULE_NAME: String = "ondemandfeature" // must match gradle module name

fun downloadOnDemandFeature(context: Context) {
    val request = SplitInstallRequest
            .newBuilder()
            .addModule(ONDEMAND_FEATURE_MODULE_NAME)
            .build()

    val splitInstallManager = create(context)

    // Initializes a variable to later track the session ID for a given request.
    var mySessionId = 0
    val listener = SplitInstallStateUpdatedListener { state ->
        if (state.sessionId() == mySessionId) {
            when (state.status()) {
                SplitInstallSessionStatus.DOWNLOADING -> {
                    val totalBytes = state.totalBytesToDownload()
                    val progress = state.bytesDownloaded()
                    Timber.d("Downloading on demand module: state DOWNLOADING")
                    Timber.d("Downloading on demand module: %d of %d bytes", progress, totalBytes)
                }
                SplitInstallSessionStatus.INSTALLED -> {
                    Timber.d("Downloading on demand module: state INSTALLED")
                    // TODO installed, now do stuff
                }
                SplitInstallSessionStatus.CANCELED -> {
                    Timber.d("Downloading on demand module: state CANCELED")
                }
                SplitInstallSessionStatus.CANCELING -> {
                    Timber.d("Downloading on demand module: state CANCELING")
                }
                SplitInstallSessionStatus.DOWNLOADED -> {
                    Timber.d("Downloading on demand module: state DOWNLOADED")
                }
                SplitInstallSessionStatus.FAILED -> {
                    Timber.d("Downloading on demand module: state FAILED")
                }
                SplitInstallSessionStatus.INSTALLING -> {
                    Timber.d("Downloading on demand module: state INSTALLING")
                }
                SplitInstallSessionStatus.PENDING -> {
                    Timber.d("Downloading on demand module: state PENDING")
                }
                SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION -> {
                    Timber.d("Downloading on demand module: state REQUIRES USER CONFIRMATION")
                }
                SplitInstallSessionStatus.UNKNOWN -> {
                    Timber.d("Downloading on demand module: state UNKNOWN")
                }
            }
        }
    }

    splitInstallManager.registerListener(listener)

    splitInstallManager
            .startInstall(request)
            .addOnSuccessListener { sessionId -> mySessionId = sessionId }
            .addOnFailureListener { exception ->
                Timber.e(exception, "Error installing ondemandfeature")
            }
}

You can see my full logs here.

Intercommunicate answered 27/11, 2019 at 19:4 Comment(3)
Did you ever find a solution for your problem? I'm stuck at the same problem but when I try the google codelab example it works just fine with internal app sharing.Lichi
Is Proguard enable?Limit
I have a problem when proguard enabled. I can not reach dynamic feature fragment.Limit
B
0

I have implemented a dynamic module in my app which is greater than 10 MB and requires user confirmation too. Your code looks fine. Please make sure you are doing the following things correctly.

  1. At (case:SplitInstallSessionStatus.INSTALLED:) make sure you create an intent to go to your dynamic activity.

    Intent intent = new Intent(); intent.setClassName("your package name", "your packagename.module.yourdynamicactivity"); startActivity(intent);

  2. Make sure your (versionCode *) and (versionName " * ") are the same in buidle.gradle file of the app and your module.

  3. In your dynamic module call this method in your activity.

    @Override protected void attachBaseContext(Context newBase) { super.attachBaseContext(newBase); SplitCompat.install(this); }

Burdett answered 22/1, 2020 at 14:21 Comment(3)
Do you have any documentation showing that #2 is actually needed? I haven't read that in any of my research on on-demand DFMs.Intercommunicate
Nope, it's not in the documentation. I had a problem with "targetsdkversion not set properly" So #2 fixed it for me. On-demand DFMs documentation looks simple but is tricky, also please make sure the app id of your app and the module is the same as "com.app" and for module"com.app.module". Let me know if you need to look at my code.Burdett
in dynamic module I think prefer SplitCompat.install(newBase != null ? newBase : this)Wini

© 2022 - 2024 — McMap. All rights reserved.