簡體   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