Dagger 2 does not generate the component class (Android, Kotlin)

a 夏天 提交于 2019-12-11 10:12:21

问题


Basically, I wanted to test if TheCoffee was automatically "injected". But I could not find DaggerMyComponent. I think I must have done something wrong, but what?

Under the MainActivity,

@Component(modules=arrayOf(MyModule::class))
@Singleton
interface MyComponent
{
    fun inject(coffee: CoffeeShop)
}

@Module
class MyModule
{
    @Provides
    @Singleton
    @ForApplication
    fun provideCoffee():Coffee
    {
        return Coffee("Bad coffee");
    }
}

data class Coffee(var Name:String)

class CoffeeShop
{
    @Inject
    var TheCoffee:Coffee? = null;
}

@Qualifier
@Retention(AnnotationRetention.RUNTIME)
annotation class ForApplication

build.gradle

apply plugin: 'kotlin-kapt'
...
kapt {
    generateStubs = true
}
....
dependencies {
    compile 'com.google.dagger:dagger-android:2.13'
    kapt 'com.google.dagger:dagger-android-processor:2.13'
    compileOnly 'com.google.dagger:dagger:2.13'
    kapt 'com.google.dagger:dagger-compiler:2.13'

来源:https://stackoverflow.com/questions/47247696/dagger-2-does-not-generate-the-component-class-android-kotlin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!