无法使用Dagger Hilt`@WorkerInject`注入Android WorkManager Worker
本文介绍了无法使用Dagger Hilt`@WorkerInject`注入Android WorkManager Worker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试按照https://developer.android.com/training/dependency-injection/hilt-jetpack#workmanager中的指南操作,但遇到以下错误
为了重现该问题,我在Dagger Hilt Example Repo中添加了GUDE中的示例代码
注意:AppNavigator
在NavigationModule中以@Binds abstract fun bindNavigator(impl: AppNavigatorImpl): AppNavigator
。
另请注意,将AppNavigator
替换为AppDatabase
无济于事。
这就是我如何从MainActivity
不确定到底出了什么问题。
更新:我已经创建了一个全新的Android项目来复制它。项目是attached to the issue#158843197。所有密钥文件源代码快照都位于GitHub Gist(如果您想快速查看)。
更新2:解决方案
除了Ianmentioned below,问题是我错过了app/build.gradle
中的Gradle依赖(在aosp#158843197中提到)
Worker
的依赖项注入现在正在工作。
推荐答案
更新(2021年3月24日):
从androidx.work-*
版本2.6.0-alpha01
开始,WorkManager
使用androidx.startup
初始化WorkManager。有关对
AndroidManifest.xml
所需的新更改,请检查this答案。
原始答案:
根据WorkManager Configuration and Initialization documentation,要在Application
上使用Configuration.Provider
接口,您必须remove the default initializer:
否则,默认初始值设定项仍将运行,并清除您的自定义初始化及其HiltWorkerFactory
。
这篇关于无法使用Dagger Hilt`@WorkerInject`注入Android WorkManager Worker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!