Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Dagger 2使用另一个库生成的类_Android_Kotlin_Dagger 2_Kapt - Fatal编程技术网

Android Dagger 2使用另一个库生成的类

Android Dagger 2使用另一个库生成的类,android,kotlin,dagger-2,kapt,Android,Kotlin,Dagger 2,Kapt,我有一个自制的库,可以生成DataMapper类 它们是通过@Singleton和@Inject注释生成的,以便能够在需要它们的地方注入它们 但当Dagger尝试创建依赖关系树时,它不起作用,此错误显示: :data:kaptGenerateStubsDebugKotlin e: /Users/me/myproject/data/build/tmp/kapt3/stubs/debug/com/myproject/data/di/DataComponent.java:11: error: [Dag

我有一个自制的库,可以生成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
DataComponent(匕首组件):

ContentDataRepository

@Singleton
class ContentDataRepository @Inject constructor(
        private val myGeneratedDataMapper: MyGeneratedDataMapper
) : ContentRepository {
    ...
}
MyGeneratedDataMapper

@Singleton
class MyGeneratedDataMapper @Inject constructor() {
   ...
}
问题是,如果我在
gradle.build
中禁用dagger依赖的kapt,那么构建,然后启用它,然后构建,它就会工作

如果我做了一个clean+构建,它就不工作了,同样的错误。
我想把它排成一行。

你可能不会喜欢我的答案,但顺序是随机的。
请看这篇文章,了解更多的解释,也许还有更多的指导,但是,如果您想验证您是否正在运行,请首先查看Gradle插件以及如何使用它们,我不知道您是否正在将AS3.2或AS3.3与androidX工件一起使用,但您可能也是这样

因此,当我在AS3.2中迁移到
androidX工件时,我遇到了一堆
NonExistentClass
错误,以

kaptGenerateStubsDebugKotlin 
:data:kaptDebugKotlin
:data:kaptDebugKotlin 
我最终发现它与Dagger本身有关,并将版本从
2.17
降级为
2.16
,现在Dagger2的最新版本是
2.18
,由于这个bug/功能,我无法使用它[他们忘记了]

更新:

我找到了解决方案,它今天刚刚发布,下面是问题跟踪链接:

因此,这个bug不在匕首中,而是在使用Jetifier时出现的,我完全忽略了在迁移过程中启用它的事实

这是我从链接复制的解决方案:

抱歉,jetifier beta01与alpha10不兼容

我们已经发布了beta02,可以解决这个问题

请尝试:


我猜你可能在计时方面有问题,我想出于某种原因,dagger在你的Classic之前就被执行了,这正是,如果你仔细观察gradle任务顺序,
kaptGenerateStubsDebugKotlin
是dagger想要访问我生成的类的地方,当我的类被生成时,是kaptDebugKotlin
任务,我想很抱歉延迟了回复。你是如何将dagger导入处理器的,如果你不导入你自己,那么你指望用户来实现它吗?我不在我的库中导入处理器,所以是的,我让用户(我)在最后的项目中实现它。
@Singleton
class MyGeneratedDataMapper @Inject constructor() {
   ...
}
kaptGenerateStubsDebugKotlin 
:data:kaptDebugKotlin
:data:kaptDebugKotlin 
buildscript {    dependencies {
       classpath 'com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta02'    } }