android.content.Context cannot be provided without an @Provides-annotated method

Viewed 3006

I am getting the following error, after hilt update to 2.32-alpha.

Even after providing the concerned element, it's complaining for it. I am quite sure it's related to scopes but unable to sort it out, Logs are as follows,

  ^C:\Users\VikramSingh\Desktop\work\Mine\mobiquity\app\build\generated\source\kapt\debug\reprator\mobiquity\MobiQuityApp_HiltComponents.java:145: error: [Dagger/MissingBinding] @dagger.hilt.android.qualifiers.ActivityContext android.content.Context cannot be provided without an @Provides-annotated method.
 public abstract static class SingletonC implements HiltWrapper_ActivityRetainedComponentManager_ActivityRetainedComponentBuilderEntryPoint,
                     ^
 A binding with matching key exists in component: reprator.mobiquity.MobiQuityApp_HiltComponents.ActivityC
  @dagger.hilt.android.qualifiers.ActivityContext android.content.Context is injected at
      reprator.mobiquity.addcity.di.AddCityModule.provideGeoCoder(context)
  android.location.Geocoder is injected at
      reprator.mobiquity.addcity.di.AddCityModule.provideReverseGeoCoding(geoCoder)
  reprator.mobiquity.addcity.ReverseGeoCoding is injected at
      reprator.mobiquity.addcity.AddLocationViewModal(�, reverseGeoCoding, �)
  reprator.mobiquity.addcity.AddLocationViewModal is injected at
      reprator.mobiquity.addcity.AddLocationViewModal_HiltModules.BindsModule.binds(arg0)
  @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() [reprator.mobiquity.MobiQuityApp_HiltComponents.SingletonC ? reprator.mobiquity.MobiQuityApp_HiltComponents.ActivityRetainedC ? reprator.mobiquity.MobiQuityApp_HiltComponents.ViewModelC][WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC).

Repository: https://github.com/TheReprator/mobiquity/tree/hilt_scope_issue

Regards, Vikram Singh

1 Answers

I think you should try to annotate the provide method with @ActivityScoped or @ActivityRetainedScoped, and another thing I noticed in your code about AddLocationViewModal, I think you should annotate it with @HiltViewModel and make it somehow like the following code:

@HiltViewModel
class AddLocationViewModal @Inject constructor(
    private val savedStateHandle: SavedStateHandle,
    private val appCoroutineDispatchers: AppCoroutineDispatchers,
    private val reverseGeoCoding: ReverseGeoCoding,
    private val locationUseCase: LocationUseCase
) : ViewModel() {...}
Related