Dagger 2不生成组件类(Android,Kotlin)

时间:2017-11-12 10:24:50

标签: android kotlin dagger-2

基本上,我想测试TheCoffee是否自动"注入"。但我找不到DaggerMyComponent。我想我一定做错了什么,但是什么?

在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'

0 个答案:

没有答案