问题描述
应用具有机器学习套件功能(翻译)。我正在尝试通过引入动态模块功能、按需加载来减小应用大小。
Following this guide 将 'com.google.mlkit:playstore-dynamic-feature-support:16.0.0-beta1' 添加到基础 apk 的 build.gradle
com.google.mlkit:translate:16.1.2 在功能模块 build.gradle 中,
一切都编译并尝试在模拟器上运行,但不幸的是在应用程序以日志开头时崩溃
java.lang.RuntimeException: Unable to get provider com.google.mlkit.common.internal.MlKitinitProvider: com.google.firebase.components.MissingDependencyException: Unsatisfied dependency for component Component<[class com.google.android.gms.internal.mlkit_translate.zzxa]>{0,type=0,deps=[Dependency{anInterface=class com.google.mlkit.common.sdkinternal.SharedPrefManager,type=required,injection=direct},Dependency{anInterface=class com.google.android.gms.internal.mlkit_translate.zzwx,injection=direct}]}: class com.google.mlkit.common.sdkinternal.SharedPrefManager
Caused by: com.google.firebase.components.MissingDependencyException: Unsatisfied dependency for component Component<[class com.google.android.gms.internal.mlkit_translate.zzxa]>{0,injection=direct}]}: class com.google.mlkit.common.sdkinternal.SharedPrefManager
哪一种没有意义。因为我添加了 playstore-dynamic-feature-support。
解决方法
要设置动态模块,您需要将 mlkit 转换依赖项从基础应用程序的 gradle 文件移动到动态模块的 gradle 构建文件。您还需要将所有相关用法移动到动态模块。因此,当应用程序启动时,它不会查找任何 mlkit 翻译依赖项。请参阅 play store on demand delivery guide 以获取逐步设置指南。