【发布时间】:2018-10-19 08:31:34
【问题描述】:
我有一个生成 DataMapper 类的自制库。
它们是使用@Singleton 和@Inject 注释生成的,以便能够将它们注入到我需要它们的地方。
但是当 Dagger 尝试创建依赖树时,它不起作用,这个错误显示:
:data:kaptGenerateStubsDebugKotlin
e: /Users/me/myproject/data/build/tmp/kapt3/stubs/debug/com/myproject/data/di/DataComponent.java:11: error: [Dagger/MissingBinding] error.NonExistentClass cannot be provided without an @Inject constructor or an @Provides-annotated method.
public abstract com.myproject.domain.repository.ContentRepository contentRepository();
^
error.NonExistentClass is injected at
com.myproject.data.repository.ContentDataRepository.<init>(…, myGeneratedDataMapper, …)
com.myproject.data.repository.ContentDataRepository is injected at
com.myproject.data.di.module.DataModule.contentRepository(contentDataRepository)
com.myproject.domain.repository.ContentRepository is provided at
com.myproject.data.di.DataComponent.contentRepository()
:data:kaptDebugKotlin
:data:kaptDebugKotlin FAILED
涉及的课程有:
DataModule(匕首模块)
@Module
class DataModule {
@Provides
@Singleton
fun contentRepository(contentDataRepository: ContentDataRepository): ContentRepository = contentDataRepository
}
DataComponent(匕首组件):
@Singleton
@Component(modules = [DataModule::class])
interface DataComponent {
fun contentRepository(): ContentRepository
}
内容数据存储库
@Singleton
class ContentDataRepository @Inject constructor(
private val myGeneratedDataMapper: MyGeneratedDataMapper
) : ContentRepository {
...
}
MyGeneratedDataMapper
@Singleton
class MyGeneratedDataMapper @Inject constructor() {
...
}
问题是,如果我在gradle.build 中禁用了匕首依赖项的 kapt,然后构建,然后启用它,然后构建,它就可以工作了。
如果我做一个干净的 + 构建,它不起作用,同样的错误。 我想让它连续工作。
【问题讨论】:
-
我猜你可能有时间问题我认为出于某种原因匕首在你的课之前执行
-
就是这样,如果你仔细查看 gradle 任务顺序,
kaptGenerateStubsDebugKotlin是 dagger 想要访问我生成的类的地方,而我的类是kaptDebugKotlin我猜的任务 -
抱歉回复延迟。你是如何将 dagger 导入你的处理器的,如果你自己不导入,那么你指望用户来实现它吗?
-
我没有在我的库中导入处理器,所以是的,我让用户(我)在最终项目中实现它。
标签: android kotlin dagger-2 kapt