'"Repeats modules with scoped bindings or declarations .. with scopes: @javax.inject.Singleton" Dagger 2
I'm trying out the Hilt DI in my test project. I've the following module that's installed in SingletonComponent which in terms of Android is applicationComponent. However when I try to scope the provide method with @Singleton, I get the following error.
MyApplication_HiltComponents.ViewModelC repeats modules with scoped bindings or declarations:
public abstract static class SingletonC implements MyApplication_GeneratedInjector,
^
- com.test.catalogue.presentation.application.MyApplication_HiltComponents.SingletonC also includes:
- com.test.catalogue.di.modules.RetrofitModule with scopes: @javax.inject.Singleton
Following is my module declaration.
RetrofitModule:
@Module(includes = {OKHttpModule.class})
@InstallIn(SingletonComponent.class)
public class RetrofitModule {
@Provides
@Singleton
public MyApi providesAPI(Retrofit retrofit) {
return retrofit.create(MyApi.class);
}
@Provides
@Singleton
public Retrofit providesRetrofit(OkHttpClient okHttpClient, GsonConverterFactory gsonConverterFactory, LiveDataAdapterFactory liveDataAdapterFactory) {
return new Retrofit.Builder()
.client(okHttpClient)
.addCallAdapterFactory(liveDataAdapterFactory)
.addConverterFactory(gsonConverterFactory)
.baseUrl(BuildConfig.API_URL)
.build();
}
@Provides
public GsonConverterFactory providesGsonConverterFactory() {
return GsonConverterFactory.create();
}
@Provides
public LiveDataAdapterFactory providesCallToLiveDataAdapterFactory() {
return new LiveDataAdapterFactory();
}
}
Build.gradle:
ext.hilt_version = '2.31.2-alpha'
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"
OkHttpModule also has @InstallIn(SingletonComponent.class) but doesn't have @Singleton scoped provides() yet since I couldn't add them because I get the same error as mentioned above.
How can I fix this? What am I doing wrong here? Am I missing something?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|