问题描述
我一整天都在调试但没有结果,我遵循了每个文档和谷歌代码实验室并将捆绑包上传到内部测试,但错误仍然存在:模块不可用,下面是我的实现:
模块 AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
package="com.appshive.shop"
>
<dist:module
dist:instant="false"
dist:title="@string/measure">
<dist:delivery>
<dist:on-demand />
</dist:delivery>
<dist:fusing dist:include="true" />
</dist:module>
</manifest>
模块 build.gradle:
plugins {
id 'com.android.dynamic-feature'
id 'kotlin-android'
id 'kotlin-kapt'
id 'kotlin-android-extensions'
}
android {
compileSdkVersion 30
buildToolsversion "30.0.2"
defaultConfig {
minSdkVersion 22
targetSdkVersion 30
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinoptions {
jvmTarget = '1.8'
}
}
并且该模块具有片段以及它们的一些依赖项。
在基础应用 Android Manifest 中:
我已经添加了这个
dynamicFeatures = [':measure']
android:name=".core.ShopApplication"
我在 build.gradle 中的应用程序 ID 是:com.appshive.ecommerce
我的应用程序类扩展了 SplitCompatApplication
class ShopApplication: SplitCompatApplication(){
override fun onCreate() {
super.onCreate()
Timber.plant(DebugTree())
SplitCompat.install(this)
startKoin {
androidContext(this@ShopApplication)
modules(listof(appModule,repoModule))
}
}
我在所有项目中只有 1 个活动:主要活动并且它包含
private lateinit var manager: SplitInstallManager
在 onCreate 中我初始化了它: manager = SplitInstallManagerFactory.create(this)
我正在检查模块是否可用我正在打开其他片段:
val request = Splitinstallrequest.newBuilder()
.addModule(name)
.build()
manager.startInstall(request).addOnSuccessListener {
maketoast("Successss")
}.addOnFailureListener { e->
maketoast(e.message.toString()+" as")
}
我正在向经理注册监听器:
override fun onPause() {
manager.unregisterListener(listener)
super.onPause()
}
override fun onResume() {
manager.registerListener(listener)
super.onResume()
}
就是这样,然后我使用我的密钥生成签名包并将其上传到内部测试,然后我将其安装在手机上,然后出现错误:错误 -2 模块不可用
我已经尝试了互联网上的所有方法,但都没有运气我不知道我错过了什么。是因为捆绑签名还是因为包装?
当我更改模块以安装时间模块时,它就像一个魅力。
解决方法
在开发此功能时,我仅使用 Playstore 的内部测试功能进行测试。
后来我知道还有另一种方法可以使用名为 Bundle Tool 的工具在本地执行此操作。
您可以从给定的链接下载它。下载Bundle Tool文件后,需要使用它生成apk。
bundletool build-apks
--bundle=app/build/outputs/bundle/debug/bundle.aab
--output=my_app.apks
附注。当我在我的应用程序中使用此功能时,我是使用 Java 代码开发它的,但我 100% 确定它也适用于 kotlin 代码。