0
votes

I'm working with Dagger2 in a multi-module project and Im having an issue with one module in particular.

I have a Room database that I'm injecting into Repository classes. The module for that looks something like this:

@Module
class RoomModule(app: Application) {
   private val database = AppDatabase.getInstance(app)

   @Provides
   @Singleton
   fun provideModelDao() = database.getModelDao()

   @Provides
   @Singleton
   fun provideAnotherModelDao() = database.getAnotherModelDao()
}

And my repository classes look like this:

class ModelRepository @Inject constructor(private val modelDao: ModelDao) {
    fun doFooWithModel() {
       // Do foo
    }
}

My repository classes are used by UseCase classes, that look something like this:

class DoFooUseCase @Inject constructor(private val repository: ModelRepository) {
    fun doFoo() {
        repository.doFooWithModel()
    }
}

And finally, Im using this UseCase class in a WebClient implementation class.

class MyWebClient @Inject constructor(private val fooUseCase: DoFooUseCase): WebClient() {
    // Web client stuff
}

Here, no problem.

The problem comes when I inject the WebClient into an activity.

class WebActivity : AppCompatActivity() {

   @Inject
   lateinit var webClient: MyWebClient    

    override fun onCreate(savedStateInstance: Bundle?) {
        super.onCreate(savedStateInstance)
        AndroidInjection.inject(this)
        webView.webViewClient = webClient
    }
}

Now, after building the project, I get this error:

MyApplicationComponent.java:24: error: cannot find symbol:
RoomModule_ProvideModelDAOFactory;

But, oddly enough, when I remove the @Inject annotation from the activity, the Dagger component builds correctly. But obviously, the app doesn't work because the lateinit var are not being injected.

What are those xxFactory classes and how can I make dagger generate them? What am I missing here? I had used dagger like this in other projects and I haven't had this issue before.

Thanks

1

1 Answers

0
votes

EDIT.

To someone else having this issue.

I was missing the Dagger Compiler dependency in the module containing the Room classes.

the dependency is:

kapt com.google.dagger:dagger-compiler:$dagger_version

or annotationProcessor if you are using JAVA instead of Kotlin.