美文网首页
记录 Kotlin 中使用 Dagger2,ButterKnif

记录 Kotlin 中使用 Dagger2,ButterKnif

作者: 13kmsteady | 来源:发表于2018-11-15 11:45 被阅读41次

在项目中引入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,ButterKnif

      本文链接:https://www.haomeiwen.com/subject/dwqggftx.html