DaggerAppComponent - unresolved reference

Viewed 5060

Please help me to connect Dagger 2 to Kotlin. My app build gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "mobile.socialboards.com"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 19
        versionName '1.0'
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
        }
    }
    configurations {
        cleanedAnnotations
        compile.exclude group: 'org.jetbrains' , module:'annotations'
    }
    productFlavors {}
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
        freeCompilerArgs = ['-Xjvm-default=enable']
    }
    lintOptions {
        abortOnError false
    }
}

kapt {
    generateStubs = true
}

dependencies {
    ...

    implementation 'com.google.dagger:dagger-android:2.14.1'
    implementation 'com.google.dagger:dagger-android-support:2.14.1' // if you use the support libraries
    implementation "com.google.dagger:dagger:2.14.1"
    kapt 'com.google.dagger:dagger-android-processor:2.12'
    kapt "com.google.dagger:dagger-compiler:2.14.1"
    compileOnly "org.glassfish:javax.annotation:3.1.1"
}

apply plugin: 'com.google.gms.google-services'

I'm making sуnc, then rebuild, but

DaggerAppComponent

cannot be found by Android Studio in my Application kotlin class. I research a lot of articles - and still don't understand whats wrong. Please help!

2 Answers

I have implemented Full MVVM (Rx, Dagger, Kotlin), just needed this two for dagger:

 implementation 'com.google.dagger:dagger:2.12'
kapt 'com.google.dagger:dagger-compiler:2.12'

If anything let me know!!

Quite straightforward, you need to create ApplicationComponent, like this:

@Singleton
@Component(modules = [
    ApplicationModule::class,
])
interface ApplicationComponent {

    @Component.Builder
    interface Builder {
        @BindsInstance
        fun application(application: Application): Builder
           fun build(): ApplicationComponent
        }
}
Related