error: [Dagger/DuplicateBindings] … is bound multiple times:

Trying to set up DI with a project I’m working on (one module per layer app), and I’ve ran into an issue that I don’t know how to fix: public abstract static class SingletonC implements FragmentGetContextFix.FragmentGetContextFixEntryPoint, ^ @Singleton @Provides @org.jetbrains.annotations.NotNull winged.example.data.DoggoApi winged.example.data.di.DataModule.provideDoggoApi() @Singleton @Provides @org.jetbrains.annotations.NotNull winged.example.data.DoggoApi winged.example.modularretrofitapp.NetworkingModule.provideDoggoApi(okhttp3.OkHttpClient) winged.example.data.DoggoApi is injected at winged.example.data.di.DataModule.provideRepository(api) winged.example.domain.repository.DoggoRepository is injected… Read More error: [Dagger/DuplicateBindings] … is bound multiple times:

How to check internet with LiveData in Android

In my application I want check internet connection and for this I want use LiveData. I write below codes, but after build project show me error! I used Hilt for dependency injection. CheckConnection class : class CheckConnection @Inject constructor(private val cm: ConnectivityManager) : LiveData<Boolean>() { constructor(application: Application) : this( application.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager ) private val… Read More How to check internet with LiveData in Android

Is it bad to inject two ViewModel objects into a composable function?

I’m using Hilt for injecting regular objects, as well as ViewModels. In a single part of my app, there is a composable function where I need to inject two ViewModel objects: @Composable fun AllProducts( allProductsViewModel: AllProductsViewModel = hiltViewModel(), authViewModel: AuthViewModel = hiltViewModel() ) { //Stuff } Is it bad to inject two ViewModel objects rather… Read More Is it bad to inject two ViewModel objects into a composable function?

Passing an interceptor to retrofit builder using dagger-hilt

I’m learning about retrofit interceptors, for work purposes I’m using dagger-hilt for the injection of dependencies to fragments etc. I wrote a custom interceptor to check for connection errors and I’m trying to add it to the Retrofit.Builder(): @Provides @Singleton fun provideApi(): StoreApi { return Retrofit.Builder() .baseUrl(Constants.BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava3CallAdapterFactory.create()) .build() .create(StoreApi::class.java) } however, I have… Read More Passing an interceptor to retrofit builder using dagger-hilt

Jetpack Compose – unresolved refence when using viewmodel value in LazyColumn

For my college project I want to use data from Firestore, and then use MVVM pattern to display the items on the Lazy Column. Here is the code of the screen of where I want the values of viewmodel to be displayed: fun HomeScreen (navController: NavController, viewModel: ArticleViewModel = hiltViewModel()){ var expanded = remember {… Read More Jetpack Compose – unresolved refence when using viewmodel value in LazyColumn

Can you use Hilt in a Java-only Android project?

According to the official integration guide, you need to add plugins { id ‘kotlin-kapt’ … } and dependencies { implementation "com.google.dagger:hilt-android:{hilt_version}" kapt "com.google.dagger:hilt-compiler:{hilt_version}" } to your build.grade file. However, when I do a gralde sync, I get the following error: Plugin [id: ‘kotlin-kapt’] was not found in any of the following sources: is it possible… Read More Can you use Hilt in a Java-only Android project?

Hilt – what is the Java equivalent to kotlin's "by viewmodels()" to inject viewmodel into activity?

I’m following Kotlin tutorial on learning Dagger Hilt for dependency injection. The tutorial uses class MainActivity: AppCompatActivity() { private val viewModel: TestViewModel by viewModels() } in the MainActivity to inject the viewmodel. It requires a dependency: implementation "androidx.activity.activity-ktx:1.1.0" to do so. I’m trying to learn hilt in Java so I’m unsure what the Java equivalent… Read More Hilt – what is the Java equivalent to kotlin's "by viewmodels()" to inject viewmodel into activity?