记录 Kotlin 中使用 Dagger2,ButterKnife 踩坑经历

在项目中引入Kotlin,添加了 kapt 插件 apply plugin: 'kotlin-kapt'。编译项目,发现无法自动生成 DaggerXxxComponent 类。报错信息如下

错误: 找不到符号
符号:   类 DaggerAppComponent
位置: 程序包 com.example.component

一顿搜索,终于解决了编译出错的问题。具体见下方

之前的依赖

  // Dagger2
    implementation "com.google.dagger:dagger:$rootProject.dagger2Version"
    annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.dagger2Version" 

修改后的依赖

// Dagger2
    implementation "com.google.dagger:dagger:$rootProject.dagger2Version"
    kapt "com.google.dagger:dagger-compiler:$rootProject.dagger2Version"

特此记录踩坑操作。

你可能感兴趣的:(记录 Kotlin 中使用 Dagger2,ButterKnife 踩坑经历)