Android Kotlin : Error Unresolved reference: DaggerAppComponent

前端 未结 4 406
悲哀的现实
悲哀的现实 2021-02-02 08:39

I have installed Kotlin plugin today into an existing project with Dagger 2. Before Kotlin was installed I had no issues with Dagger. However, now the compiler complains :

相关标签:
4条回答
  • 2021-02-02 08:50

    At first, It gives an error after rebuild:

    Unresolved reference: DaggerAppComponent

    You should try to import (Alt + Enter) that component.

    0 讨论(0)
  • 2021-02-02 08:54

    I was getting the same error message, but my case was different than yours. The unresolved reference appeared only when generating signed APK. This is how I solved it:

    app/build.gradle

    kapt {
        generateStubs = true
    }
    
    dependencies {
        //...
        implementation 'com.google.dagger:dagger:2.9'
        kapt 'com.google.dagger:dagger-compiler:2.9'
    }
    

    I can now deploy my signed APK without errors

    0 讨论(0)
  • 2021-02-02 09:07
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-kapt'   
    

    And in your dependencies:

    implementation "com.google.dagger:dagger:2.x"
    implementation "com.google.dagger:dagger-android:2.x"
    implementation "com.google.dagger:dagger-android-support:2.x"
    kapt "com.google.dagger:dagger-compiler:2.x"
    kapt "com.google.dagger:dagger-android-processor:2.x"
    
    0 讨论(0)
  • 2021-02-02 09:09

    Do not use private for inject dagger in Kotlin, use it like this for Kotlin

    @Inject
         internal lateinit
    
    0 讨论(0)
提交回复
热议问题