Dagger 2: @Component.Builder is missing setters for required modules or components: [appi.example.com.dagger.AppModule]`

前端 未结 3 895
失恋的感觉
失恋的感觉 2020-12-13 00:00

I\'m configuring the new Dagger Android module but I got this error Here\'s my Component:

@AppScope
@Component(modules = {AppModule.class, NetModule.class})
         


        
相关标签:
3条回答
  • 2020-12-13 00:40

    Remove the below code from the AppModule.class and rebuild the project

        @Provides
        @Singleton
        Application provideContext(SomeApplication application) {
            return application;
        }
    
    0 讨论(0)
  • 2020-12-13 00:40

    I think this provides a somewhat clearer explanation on the use of @BindsInstance and removal of @Provides Application, Dagger 2 Component Builder:

    @BindsInstance What?

    Here’s the definition :

    Marks a method on a component builder or subcomponent builder that allows an instance to be bound to some type within the component. — source

    WHAAT? I don’t understand it either

    0 讨论(0)
  • 2020-12-13 00:45

    In my case I was using an object Module, so I had to annotate provider method with @JvmStatic

    @Module
    object GsonModule {
    
        @JvmStatic
        @Singleton
        @Provides
        fun provideGson() = Gson()
    
    }
    
    0 讨论(0)
提交回复
热议问题