How to get kapt to work with Kotlin DSL in android...
# android
m
How to get kapt to work with Kotlin DSL in android. I've searched this thread but couldn't get a proper answer. I'm basically trying to get Hilt working on Kotlin DSL (in android). I've tried the following
Copy code
plugins {
    kotlin("kapt")
}
and
apply(plugin = "kotlin-kapt")
But when I try to add this, it doesn't work.
Copy code
dependencies {
    kapt(SupportLibs.ANDROID_DAGGER_HILT_COMPILER)
}
It imports "org.jetbrains.kotlin.kapt3.base.Kapt.kapt" which says Type mismatch. Required: KaptOptions Found: String Am I missing something. I'm new to Kotlin DSL in android. I've searched for it a lot but couldn't find anything. Any help would be highly appreciated. Thanks Slack Conversation
j
This is working for me
m
How do you use kapt in the dependency block? I still get an error when I use kapt("something"). kapt doesn't auto import. It needs importing. Is that the usual way?
s
I use a different way of defining dependencies using kotlin dsl, it's not exactly the answer to your question. But I define them using extensions on DependencyHandler. You can check it out here https://github.com/sm3saurabh/RestaurantFinder/blob/dev/buildSrc/src/main/java/Dependencies.kt
By the way. Defining it like this also works for me
Copy code
plugins {
    kotlin("kapt")
}

dependencies {
    kapt(DependencyString)
}
Which android studio version are you on?
m
Android Studio Canary 4.1
s
After defining dependency with kapt, can you run ./gradlew tasks once.
That will give you more insights.
m
Okay, I'm looking into your repo and trying to make kapt work as you've written. I'll run ./gradlew tasks too now.
s
Were you able to make it work?
m
I created a new project, followed your buildSrc structure for dependencies. And I added the hilt dagger plugin and I injected a variable and it worked. So using kapt in the way you suggested works. I'll provide the github link once I push the code for reference.
s
I am glad that it worked out for you.
m
Thank you for your help
134 Views