最近没事玩玩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
- 记住版本号 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"
}
}
- 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'
}