繁体   English   中英

App Bundle,在动态功能模块中,安装前可用的模块

[英]App Bundle, In Dynamic Feature Module, Module available before install

我尝试在我的应用程序中实现动态功能模块。 我在活动中有按钮。 当用户单击时,我检查模块是否已安装。 如果不是,我使用 startInstall(request) 开始安装。 但我总是去其他州。

代码

    if (manager.installedModules.contains("sample")) {
-----> Always go to this block 
                Toast.makeText(this, "Already Downloaded", Toast.LENGTH_SHORT).show()
                Intent().setClassName(packageName, "com.example.sample.SampleActivity")
                        .also {
                            startActivity(it)
                        }
            } else {
               // Never came to this state
                // Create request to install a feature module by name.
                val request = SplitInstallRequest.newBuilder()
                        .addModule("sample")
                        .build()
                // Load and install the requested feature module.
                manager.startInstall(request)
            }

在动态功能模块中,我设置了onDemand="true"

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
package="com.example.sample">

<dist:module
    dist:onDemand="true"
    dist:title="@string/title_sample">
    <dist:fusing dist:include="true" />
</dist:module>

<application>
    <activity android:name="com.example.sample.SampleActivity">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
        </intent-filter>
    </activity>
</application>

目前,测试按需交付实施的唯一方法是将 .aab 上传到 PlayStore。

Android Studio 的标准部署将所有模块部署到连接的设备。

在开发环境中,流程是正确的,模块在部署到设备时已经安装。

至于代码,请看示例 app ,特别是MainActivity的下载和侦听器实现。

另一种在本地测试动态功能模块而不将其上传到 Play 商店的方法是使用bundle-tool

bundle-tool 使用一个标志--local-testing来模拟确切的环境,并且可以看到下载的功能模块

./gradlew bundleDebug

bundletool build-apks --overwrite --local-testing --bundle path/to/bundle.aab --output path/to/apkset.apks

bundletool install-apks --apks path/to/apkset.apks

更多详情请参考以下链接: https : //medium.com/androiddevelopers/local-development-and-testing-with-fakesplitinstallmanager-57083e1840a4

add split="dynamic-feature-test" in your manifest
split="split_name" : Defines the name of the module, which your app specifies when requesting an on demand module using the Play Core Library.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM