首页 > 解决方案 > Android动态功能卡在安装视图虽然它说它已安装

问题描述

我在我的应用程序中使用动态功能模块,这是我的App课程 -

@HiltAndroidApp
class DogApp : SplitCompatApplication() {

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

这是我的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)
            }
    }

当我构建 apk 并在我的设备/模拟器上运行时,我看到永远存在的“安装模块”并且我看到了日志 -

Installed

Success

这是我永远看到的屏幕-

在此处输入图像描述

我在做什么错误?

标签: androidkotlingoogle-playandroid-moduledynamic-feature-module

解决方案


你用导航了2.3.2吗?我发现此更改后存在问题。回滚到2.3.1或使用您自己的进度 UI 而不是DefaultProgressFragment将解决此问题。


推荐阅读