最近没事玩玩kotlin,随便学习了一波dagger2,打配合使用下,但是出现了些问题,记录出来

问题

  • Unresolved reference: DaggerAddFavoriteComponent
  • Compilation error. See log for more details
  • Caused by: org.gradle.api.GradleException: Compilation error. See log for more details
  • org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:app:compileDebugKotlin’.

配置

  • kotlin插件
    • File->Settings->Plugins
    • kotlin配合dagger2出现的问题
    • 记住版本号 1.2.71
  • project的build.gradle
buildscript {
   ext.kotlin_version = '1.2.71'
   repositories {
       google()
       jcenter()
   }
   dependencies {
       classpath 'com.android.tools.build:gradle:3.2.0'
       classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
   }
}

kotlin配合dagger2出现的问题

  • app目录build.gradle
apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
kapt {
   generateStubs = true
}
...
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
   //一定需要用annotationProcessor
   annotationProcessor "com.google.dagger:dagger-compiler:2.15"
   implementation 'com.google.dagger:dagger:2.15'
}

相关文章:

  • 2021-06-05
  • 2021-09-12
  • 2021-07-05
  • 2021-08-20
  • 2021-11-04
  • 2021-05-28
  • 2021-08-22
猜你喜欢
  • 2021-04-30
  • 2021-07-22
  • 2021-12-19
  • 2021-08-11
  • 2021-09-18
  • 2021-04-18
  • 2021-07-04
相关资源
相似解决方案