0

The code provided bellow still has an Unresolved reference to DaggerAppComponent. I can't find an error.

Already did Rebuild

Here is my Application class

class CinemaApplication : SplitCompatApplication() {

    private lateinit var context: Context

    val appComponent: AppComponent by lazy {
        DaggerAppComponent.factory().create(applicationContext)
    }
}

Here is my AppComponent class

@Component
interface AppComponent {

    @Component.Factory
    interface Factory {
        fun create(@BindsInstance context: Context): AppComponent
    }

    fun inject(activity: NavHostActivity)
}

Here is my Activity class

class NavHostActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {

        (application as CinemaApplication).appComponent.inject(this)

        super.onCreate(savedInstanceState)
    }
  • In the Line DaggerAppComponent.factory().create(applicationContext) did you try to change "applicationContext to MainActivity.class(for example) or use getapplicationcontext() – Ruben Meiring Nov 06 '19 at 12:59
  • 1
    @RubenMeiring getapplicationcontext() = applicationcontext in Kotlin world. – Sergejs Bogdanovs Nov 06 '19 at 13:09
  • https://stackoverflow.com/questions/42843996/android-kotlin-error-unresolved-reference-daggerappcomponent Maybe something here could help you – Ruben Meiring Nov 06 '19 at 13:14

1 Answers1

1

Try using kapt

apply plugin: 'kotlin-kapt'

dependencies {
    implementation "com.google.dagger:dagger:2.22"
    kapt "com.google.dagger:dagger-compiler:2.22"
}
Md. Asaduzzaman
  • 14,963
  • 2
  • 34
  • 46