I try to implement dynamic feature module in my app. I have button in Activity. When user click I check module already installed or not. if not i start Install using startInstall(request). But I always goes to else state.
Code
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)
}
In Dynamic feature module I set 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>
Currently the only way to test your implementation of onDemand delivery is by uploading the .aab to the PlayStore.
The standard deployment from Android Studio deploys all modules to the attached device.
In a development environment the flow is correct, that the module is already installed when it's deployed to device.
As for code, take a look at the sample app , in particular the download and listener implementation of MainActivity .
Another way of testing dynamic feature modules locally, without being uploading it to play store, is to use bundle-tool .
bundle-tool uses a flag --local-testing
which emulates the exact environment and the feature module can be seen downloading
./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
Refer to the following link for more details: 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.