Dagger and Kotlin. Dagger doesn't generate component classes
Solution 1:
You need to have the kapt processor in build.gradle:
kapt {
generateStubs = true
}
dependencies {
...
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'com.google.dagger:dagger:2.0.2'
kapt 'com.google.dagger:dagger-compiler:2.0.2'
...
}
This extension will generate the code for dagger.
Additionally, for newer gradle versions, you can also apply the plugin in your build.gradle:
apply plugin: 'kotlin-kapt'
dependencies {
...
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'com.google.dagger:dagger:2.0.2'
kapt 'com.google.dagger:dagger-compiler:2.0.2'
...
}
You can check this project for reference
Solution 2:
I don't know when this change happened, but on 1.1.2 of the Kotlin gradle plugin you replace this (in your module's build.gradle
):
kapt {
generateStubs = true
}
with this:
apply plugin: 'kotlin-kapt'
and then make sure to replace dependencies that use annotationProcessor
with kapt
.
For example, the old way would be to use:
annotationProcessor (
'some.library:one:1.0'
...
'some.library.n:n.0'
)
and now you use:
kapt (
'some.library:one:1.0'
...
'some.library.n:n.0'
)