应用程序捆绑包,在动态功能模块中,安装前可用的模块

时间:2018-11-13 10:17:35

标签: android android-app-bundle

我尝试在我的应用程序中实现动态功能模块。我在活动中有按钮。当用户单击我检查模块是否已安装。如果没有,我使用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>

3 个答案:

答案 0 :(得分:3)

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

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

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

关于代码,请看一下sample app,特别是MainActivity的下载和侦听器实现。

答案 1 :(得分:1)

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

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

答案 2 :(得分:-1)

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.
相关问题