android - 无法分析 : org. jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while annotation processing

标签 android kotlin dagger-2 dagger

我正在探索 android 支持的 dagger 生命周期以在 Kotlin 中注入(inject)依赖项,但它们总是无法生成 dagger 依赖项代码。失败消息发生的错误如下:

    public abstract interface MainComponent {
                    ^
   java.lang.IllegalStateException: 
   failed to analyze: org.jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while annotation processing

这里附上MainComponent.kt

@Singleton
@Component(modules = arrayOf(AndroidSupportInjectionModule::class,AndroidInjectionModule::class,AppModule::class, NetworkModule::class, ActivityBuilder::class))
open interface MainComponent{

    @Component.Builder
    interface Builder {
        @BindsInstance
        fun application(application: Application): Builder
        fun build(): MainComponent
    }

    fun inject(app: ActifyApplication)
}

我尝试了不同的解决方案,例如 kapt enable true in app level gradle 但尚未修复。请给出一些见解为什么总是出现这种情况。非常感谢您的帮助。提前致谢。

最佳答案

你好我遇到这种问题其实是成员变量不对应导致的比如我

@Module
class ApiModule {

    @Provides
    fun provideBookService(): AppApi {
        return AppApi.instance
    }
}

这是 AppApi。实例作为应用程序。实例

关于android - 无法分析 : org. jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while annotation processing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47385801/

相关文章:

android - 如何使用 dagger2 注入(inject)没有任何 Activity 或 fragment 的 java 类

android - 为 QA 工作备份 Android 模拟器

kotlin - JetPack 撰写 : Adding click duration

android - Kotlin Android底部导航 fragment setRetainInstance(true)

android - 如何从任务中删除监听器?

android - Dagger 2 : Gradle module dependency with implementation in another module

java - 除了测试,为什么我们需要 Dagger 2?

Activity 中的 Android webview 不呈现复选框/单选按钮

android - 单元测试 : How to verify and mock onCompleted for an Observable in RxJava within Android

android - 图像在另一台设备上模糊