Dagger2 Fails To Bindsinstance For Application Object
I'm following this article in order to make Dagger 2 to directly create a module for me. However I keep getting this error: Error:(10, 1) error: @Component.Builder is missing sette
Solution 1:
Dagger can't create your module because it does not have an empty default constructor. Instead you declare it as class AppModule (private val application: Application)
, so you need to manually create the module and add it to the component—as hinted by the error.
DaggerAppComponent.builder()
.application(this) // bind application to component builder// where is the module?.build()
While this binds the application, you do not add the module—and as mentioned Dagger can't create it because you declared constructor arguments.
It seems like you're not using the constructor argument, so just delete it and it will work.
Solution 2:
I guess it is because of the fact that you have your custom constructor that takes Application
as parameter
try adding
funappModule(application: Application): Builder
to your
@Component.Builder
interfaceBuilder {
and initialize it when you create the component in your Application subclass
overridefunapplicationInjector(): AndroidInjector<out DaggerApplication> {
return DaggerAppComponent.builder()
.application(this)
.appModule(AppModule(this))
.build()
}
Post a Comment for "Dagger2 Fails To Bindsinstance For Application Object"