I have a viewmodel for activity
@HiltViewModel
class MainViewModel @Inject constructor(
private val repository: UserRepository
) : ViewModel() {
}
Repository interface
interface UserRepository {
suspend fun loginUser(username: String, password: String): Pair<Boolean, String>
}
User data source class is as follows
internal class UserDataSource @Inject constructor(private val octaveApi: OctaveApi) :
UserRepository {
override suspend fun loginUser(username: String, password: String): Pair<Boolean, String> {
return Pair(false, "unsucess")
}
}
This is my dagger implementation
@Module
@InstallIn(SingletonComponent::class)
abstract class ApiModule {
@Module
@InstallIn(SingletonComponent::class)
object Providers {
@Provides
@Singleton
internal fun provideOctaveApi(retrofit: Retrofit): OctaveApi =
retrofit.create(OctaveApi::class.java)
}
}
@Module
@InstallIn(ActivityRetainedComponent::class)
abstract class RetainedDataModule {
@Binds
internal abstract fun bindUserRepository(userDataSource: UserDataSource): UserRepository
}
When I build the project I get this error
/OctaveDashboard/app/build/generated/source/kapt/stagingExternalDebug/com/octave/OctaveApplication_HiltComponents.java:125: error: [Dagger/MissingBinding] com.octave.data.user.UserRepository cannot be provided without an @Provides-annotated method.
public abstract static class SingletonC implements OctaveApplication_GeneratedInjector,
^
com.octave.data.user.UserRepository is injected at
com.octave.MainViewModel(cornersRepository)
com.octave.MainViewModel is injected at
com.octave.MainViewModel_HiltModules.BindsModule.binds(vm)
@dagger.hilt.android.internal.lifecycle.HiltViewModelMap java.util.Map<java.lang.String,javax.inject.Provider<androidx.lifecycle.ViewModel>> is requested at
dagger.hilt.android.internal.lifecycle.HiltViewModelFactory.ViewModelFactoriesEntryPoint.getHiltViewModelMap() [com.octave.OctaveApplication_HiltComponents.SingletonC → com.octave.OctaveApplication_HiltComponents.ActivityRetainedC → com.octave.OctaveApplication_HiltComponents.ViewModelC]
Can't seem to figure out what's causing the issue.
I was missing module dependencies in my app module which was creating this issue. Was able to fix by including it.