2

I use dynamic feature module in my app and here is my App class -

@HiltAndroidApp
class DogApp : SplitCompatApplication() {

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        SplitCompat.install(this)
    }
}

Here is my MainActivity -

private var sessionId: Int = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        fetchModules()
    }

    private fun fetchModules() {
        val splitInstallManager = SplitInstallManagerFactory.create(this)

        val request = SplitInstallRequest
            .newBuilder()
            .addModule("dogProfile")
            .build()

        val listener =
            SplitInstallStateUpdatedListener { splitInstallSessionState ->
                if (splitInstallSessionState.sessionId() == sessionId) {
                    when (splitInstallSessionState.status()) {
                        SplitInstallSessionStatus.INSTALLED -> {
                            Log.e("hi", "Installed")
                        }
                        SplitInstallSessionStatus.DOWNLOADING -> {
                            val totalBytes = splitInstallSessionState.totalBytesToDownload()
                            val progress = splitInstallSessionState.bytesDownloaded()
                            Log.e("hi", "Downloading$totalBytes...$progress")
                        }
                        SplitInstallSessionStatus.INSTALLING -> {
                            Log.e("hi", "Installing")
                        }
                    }
                }
            }

        splitInstallManager.registerListener(listener)

        splitInstallManager.startInstall(request)
            .addOnFailureListener { e -> Log.e("hi", "Exception: $e") }
            .addOnSuccessListener {
                Log.e("hi", "Success")
                sessionId = it
                val navHostFragment =
                    supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
                navHostFragment.navController.navigate(R.id.homeView)
            }
    }

When I build the apk and run on my device/emulator, I see "Installing Module" that stays forever and I see the logs -

Installed

Success

Here is the screen I see forever -

enter image description here

What is the mistake I am doing?

auspicious99
  • 3,902
  • 1
  • 44
  • 58
Ma2340
  • 647
  • 2
  • 17
  • 34

1 Answers1

3

Did you use navigation 2.3.2? I found there is an issue after this change. Rollback to 2.3.1 or use your own progress UI instead of DefaultProgressFragment will fix this issue.

Yu-Hsuan
  • 505
  • 4
  • 9
  • great! this fixed my issue but I get an error now - SplitInstallService : Failed to bind to the service. DynamicInstallManager: Error requesting install of MyApp.dogProfile: Failed to bind to the service. DefaultProgressFragment: Installation failed with error -100 – Ma2340 Dec 14 '20 at 21:49
  • It depends on how you test DFM. If you don't use `FakeSplitInstallManager` then the best way to test DFM flow is to upload to [internal app sharing](https://support.google.com/googleplay/android-developer/answer/9844679) – Yu-Hsuan Dec 15 '20 at 04:28