Dagger: IllegalArgumentException: No injector factory bound for Class
I believe you have forgot to put @ContributesAndroidInjector
annotation:
@Module public abstract class ActivityModule { @ContributesAndroidInjector abstract ProductListActivity contributeProductListActivity(); @ContributesAndroidInjector abstract ProductDetailsActivity contributeProductDetailsActivity(); }
And include ViewModelModule
within AppModule
:
@Module(includes = ViewModelModule.class) class AppModule { ... }
See this code that you have wrote:
@Provides@SingletonProductListRepository provideProductListRepository(ProductListRepository repository) { return repository;}
What do you expect to happen? You are telling dagger "hey, dagger, whenever I ask you to provide me ProductListRepository
then create(return) that object using ProductListRepository
". That's not gonna work out.
Most possibly what you intended was "hey, dagger, whenever I ask you to provide me an implementation of ProductListRepository
then create(return) that object using ProductListRepositoryImpl
":
@Provides@SingletonProductListRepository provideProductListRepository(ProductListRepositoryImpl repository) { return repository;}
Which may be substituted with following:
@Binds@Singletonabstract ProductListRepository provideProductListRepository(ProductListRepositoryImpl repository);
For this error: "Dagger: IllegalArgumentException: No injector factory bound for Class"
If you are using Navigation Component with Single Activity, you can see this error.
What should you do?
Please check your @Module abstract class FragmentProvider { ... } because you need to add your Fragment inside of it as Contribute.
@Moduleabstract class FragmentProvider { @ContributesAndroidInjector // <-- Do not forget this line. abstract fun contributeYourNewFragment(): YourNewFragment}
Using the @contrubutesAndroidInjector requires an additional annotationProcessor.
Add this line to your gradle build file:
annotationProcessor 'com.google.dagger:dagger-android-processor:2.11'