CustomScope may not reference bindings with different scopes

后端 未结 1 1030
醉梦人生
醉梦人生 2021-01-17 16:56

I am new to dagger, I have defined my application component like this

@Singleton
@Component(modules = {ApplicationModule.class})
public interface Application         


        
1条回答
  •  孤城傲影
    2021-01-17 17:27

    Any module's @Provides method may only have the same scope as the component they are part of. Read more here.

    In your case LocationProviderModule is part of the LocationProviderComponent which is scoped with @LocationScope whereas the provides methods in that module uses the @Singleton scope. This is exactly what Dagger is complaining about:

    LocationProviderComponent scoped with LocationScope may not reference bindings with different scopes

    It is also pointing to where the problem is:

    @Singleton @Provides FusedLocationProviderClient LocationProviderModule.provideFusedLocationProviderClient(android.content.Context)
    @Singleton @Provides LocationRequest.module.LocationProviderModule.provideLocationRequest()
    

    Instead of using @Singleton, you just need to use @LocationScope in the LocationProviderModule.

    0 讨论(0)
提交回复
热议问题