Dat053 — How to setup annotation processor on Android with Kotlin
1 min readNov 1, 2018
Some library uses the annotation processor to annotate code to be changed in compile time. Here is how to set it up in an Android project that uses Kotlin.
- add
apply plugin: ‘kotlin-kapt’
to app’s build.gradle - change
annotationProcessor
tokapt
For example:
Dagger 2
Java version:
dependencies {
implementation 'com.google.dagger:dagger:2.18'
annotationProcessor 'com.google.dagger:dagger-compiler:2.18'
}
Kotlin version:
apply plugin: 'kotlin-kapt'dependencies {
implementation 'com.google.dagger:dagger:2.18'
annotationProcessor 'com.google.dagger:dagger-compiler:2.18'
}
Example project:
Same goes to
AutoValue
api "com.google.auto.value:auto-value-annotations:1.6.2"
kapt "com.google.auto.value:auto-value:1.6.2"
ButterKnife
implementation 'com.jakewharton:butterknife:9.0.0-rc1'
kapt 'com.jakewharton:butterknife-compiler:9.0.0-rc1'