Dagger and Kotlin. Dagger doesn't generate component classes

前端 未结 5 1274
无人共我
无人共我 2021-02-06 21:29

I\'m new with kotlin and Dagger. I have a little problem that I do not how to solve and I don\'t find a solution.

So this is what I have:

@Module
class A         


        
5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-06 21:54

    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

提交回复
热议问题