I'm getting Android dagger cannot be provided without an Provides-annotated method inside Activity file

Viewed 38

In a large codebase, I have 3 classes at concern. DataDao.kt, DataManager.kt, and InfoPageActivity.kt.

The DataManager injects DataDao and it has get function for retriving data. I'm injecting this DataManager in the InfoPageActivity to access the get method and display the info.

import javax.inject.Inject
import pkg.database.DataDao

class DataManager @Inject constructor(
    val dataDao: DataDao
) : ManagerInterface {

    ...code...

    fun getData(): String {
        return dataDao.get().toString()
    }
}

Then I have

import javax.inject.Inject
import pkg.managers.DataManager

class InfoPageActivity : AppCompatActivity() {
    @Inject
    lateinit var dataManager: DataManager

    override fun onCreate(savedInstanceState: Bundle?){
        AndroidInjection.inject(this)
        super.onCreate(savedInstanceState)
        setContentView(R.layout.info_page)
    }

    override fun onStart() {
        super.onStart()
        setDataInfo()
    }
 
    fun setDataInfo() {
        val info = dataManager.getData()
        .....code.....
    }
}

I'm getting the following error message

ask :kaptDebugUnitTestKotlin FAILED
..../TestApplicationComponent.java:12: error: [dagger.android.AndroidInjector.inject(T)] pkg.database.Datadao cannot be provided without an @Provides-annotated method.
public abstract interface TestApplicationComponent {
                ^
      pkg.database.Datadao is injected at
          pkg.managers.DataManager.<init>(…, arg2, …)
      pkg.managers.DataManager is injected at
          pkg.activities.InfoPageActivity
      pkg.activities.InfoPageActivity is injected at
          dagger.android.AndroidInjector.inject(arg0)warning: The following options were not recognized by any processor: '[room.schemaLocation, kapt.kotlin.generated]'[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: android.arch.persistence.room.RoomProcessor (NON_INCREMENTAL), com.google.auto.value.processor.AutoAnnotationProcessor (NON_INCREMENTAL), com.google.auto.value.processor.AutoValueBuilderProcessor (NON_INCREMENTAL), com.google.auto.value.processor.AutoValueProcessor (NON_INCREMENTAL), dagger.internal.codegen.ComponentProcessor (NON_INCREMENTAL), com.google.auto.service.processor.AutoServiceProcessor (NON_INCREMENTAL), dagger.android.processor.AndroidProcessor (NON_INCREMENTAL).

Not exactly sure why I'm getting this error

1 Answers

annotate it your activity class with @AndroidEntryPoint enter image description here

Related