Questions tagged [dagger-hilt]

Hilt is a Dagger2-based dependency injection library for Android.

The goals of Hilt are:

  • To simplify Dagger-related infrastructure for Android apps.
  • To create a standard set of components and scopes to ease setup, readability/understanding, and code sharing between apps.
  • To provide an easy way to provision different bindings to various build types (e.g. testing, debug, or release).
1333 questions
8
votes
2 answers

Why does injection Context into ViewModel with Hilt cause the error "could not be resolved"?

I use hilt_version = '2.41' in my project, I have read the article. I hope to inject Context into ViewModel, so I write Code A based that article. When I compile the Code A, I get the Result A, how can I fix the problems ? Code…
HelloCW
  • 843
  • 22
  • 125
  • 310
8
votes
3 answers

Android studio Bumblebee build.gradle root project can't add classpath dependencies

I'm trying to implement dagger-hilt in my new project but I see some differences in the new Android studio version (Bumblebee 2021.1.1): buildscript { ext { compose_version = '1.0.5' hilt_version = '2.40.5' } }// Top-level…
Loïc Jackotin
  • 563
  • 3
  • 12
8
votes
2 answers

Jetpack Compose & Navigation: Problems share ViewModel in nested graph

According to this example I implemented shared viewModels in a nested navigation graph. Setup Nested Graph: private fun NavGraphBuilder.accountGraph(navController: NavHostController) { navigation( startDestination = "main", route =…
8
votes
1 answer

Can I use @Inject lateinit var navigator: AppNavigatorImpl instead of @Binds abstract fun bindNavigator(impl: AppNavigatorImpl): AppNavigator?

I'm learning dependency injection by the article with the project。 The Code A need instance an object navigator by dependency injection , so the author use Code B to implement it, you can see it here. I'm very strange that the class AppNavigatorImpl…
HelloCW
  • 843
  • 22
  • 125
  • 310
8
votes
2 answers

@InstallIn, can only be used with @DefineComponent-annotated classes, but found: [com.abc.xyz.AppClass]

As per documentation for Hilt, I completed all the steps Add Class Path to Project Module classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version" Add Plugins plugins { id "kotlin-kapt" id("dagger.hilt.android.plugin") } Add…
Feroz Khan
  • 2,396
  • 5
  • 20
  • 37
8
votes
1 answer

Hilt: Why is ActivityRetainedScoped vs ViewModelScoped

I'm trying to understand why is ActivityRetainedScoped introduced for DI in Hilt. It looks to me that the scope is identical to what ViewModelScoped should do. I was under the impression that scoped worked like this: AppScope (singleton) >…
frankelot
  • 13,666
  • 16
  • 54
  • 89
8
votes
1 answer

Android Hilt cannot be provided without an @Provides-annotated method. in repository Interface Class

I'm getting this error error: [Dagger / MissingBinding] com.eduramza.domain.repositories.RemoteRepository cannot be provided without an @ Provides-annotated method. when implementing my repository interface with android hilt. That's because my…
8
votes
1 answer

How to use NavController in compose ViewModel via hilt

I am using jetpack compose with the navigation compose library to navigate from one screen to the next. Usually you would have a ViewModel that would take care of user interactions (e.g.: viewModel.addItem()). In order to fulfill the addItem command…
Moritz
  • 10,124
  • 7
  • 51
  • 61
8
votes
1 answer

Dagger Hilt error injecting ActivityContext

I'm injecting with Dagger-Hilt a class with a dependency on @ActivityContext in a ViewModel, this module is installed in ActivityComponent and scoped to activity and it's throwing me an error whenever I try to compile. For your information I have…
Barrufet
  • 495
  • 1
  • 11
  • 33
8
votes
3 answers

Dagger - Hilt : Do we need to mark all activities with @AndroidEntryPoint

So my question is as I am getting started with Hilt, do we need to mark all activities with @AndroidEntryPoint annotation or can we just create a BaseActivity and extend it to AppCompactActivity and mark that single class as the entry point? Will…
Shayan khan
  • 311
  • 5
  • 12
8
votes
2 answers

How to provide Context with Hilt Android?

I am trying to migrate a project to Hilt but facing the below issue, not sure how to pass Context with Hilt. If I remove provideContext method then it complains with the below error: error: [Dagger/MissingBinding]…
AndroidDev
  • 5,193
  • 5
  • 37
  • 68
8
votes
3 answers

Can not inject workmanager constructor with Hilt

I'm developing an Android app. and I'm trying to use hilt with workmanager constructor but it does not work and gives me this error : 2020-08-18 19:01:09.989 18125-18759/com. E/WM-WorkerFactory: Could not instantiate…
8
votes
3 answers

Hilt ClassCastException: ViewComponentManager$FragmentContextWrapper cannot be cast to AppCompatActivity

I have this code where I show Dialog Fragment when clicking a viewHolder item in Adapter SpecialRequestNotFoundBottomSheetDialog { requestItem?.specialRequestEntity?.id?.let { id -> onCancelReasonsSelected(id, it) } …
Mohamed Ibrahim
  • 3,714
  • 2
  • 22
  • 44
8
votes
2 answers

Unresolved reference @HiltAndroidApp or any other Hilt annotation in Android

I have done everything properly but still, I can't use Hilt in my project. build.gradle(:app) apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin:…
7
votes
0 answers

(Solved) Multiple values are not allowed for plugin option androidx.compose.compiler.plugins.kotlin:reportsDestination

I'm using Android Studio for Android development with Kotlin. I have more than 40 Android modules in the project: some of them are Java module, some of theme are android module. Kotlin Version = "1.8.20" Hilt Version = "2.45" Compose BOM Version =…