Android 动态功能卡在安装视图中,尽管它说已安装

Android dynamic feature stuck at installing view although it says it is installed

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

@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)
            }
    }

当我在 device/emulator 上构建 apk 和 运行 时,我看到“安装模块”永远存在 我看到了日志 -

Installed

Success

这是我永远看到的屏幕 -

我做错了什么?

你用过导航吗2.3.2?我发现 this change 之后有问题。回滚到 2.3.1 或使用您自己的进度 UI 而不是 DefaultProgressFragment 将解决此问题。