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
10
votes
1 answer

Hilt Injection in Companion Objects

I am new to Hilt/Dagger and I have not found a good example of injecting in a companion object. Here is my singleton and data class below. I am trying to use the TargetNumber manager in the create() function. I am looking for syntax help and…
Kerry
  • 283
  • 2
  • 16
10
votes
1 answer

Injecting ViewModel into ViewModel with Hilt

I'm currently working on a big project where I have a ViewModelA using MediatorLiveData to observe other LiveData sources. I would like to have this ViewModelA observing data from a ViewModelB. One way to solve this would be having the Fragment…
user14999039
10
votes
1 answer

Hilt build fails on CoroutineDispatcher injection

Not sure why this is failing build. Everything seems to be in check class MapObjectRepositoryIMPL @Inject constructor( @ApplicationContext context : Context, val mapObjectDao: MapObjectDao, val barrechatNetwork: BarreNetwork, …
chrisdottel
  • 1,053
  • 1
  • 12
  • 21
10
votes
3 answers

Error in supressing @InstallIn check whilst migrating from Dagger to Hilt using flag -Adagger.hilt.disableModulesHaveInstallInCheck=true

I have been recently trying to migrate my Android App from Dagger to Hilt. I would like to carry out the entire migration in phases and hence was trying to suppress the Hilt warning for not using @InstallIn for modules. Have been following the…
androidRajza
  • 103
  • 1
  • 4
10
votes
1 answer

Dagger with Hilt inject ActivityContext in adapter from module

I'm using dagger and hilt and i want to inject @ActivityContext from a module to an Adapter but i'm getting this error - ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1ANTLR Runtime version 4.5.3…
Naresh NK
  • 1,036
  • 1
  • 9
  • 16
10
votes
1 answer

Hilt Fragments must be attached to an @AndroidEntryPoint Activity. Found: class

Is it mandatory to add @AndroidEntryPoint annotation on all dependent classes like fragment dependent upon activity. Is there any alternative solution for overcome this exception?
M.Muzammil
  • 643
  • 9
  • 18
9
votes
4 answers

App Immediatley crashes once app runs with error ClassNotFoundException: Didn't find class application on path: DexPathList

Starting a new project and I am experiencing the following error... I have tried other solutions but seem to be dated Steps I have tried: Double checked plugins (listed below) Instance Run (not listed) tried using kapt in-place of…
9
votes
5 answers

Hilt - How to inject ViewModel interface?

Based on the Hilt tutorial, ViewModels needs to be inject the following way: @HiltViewModel class ExampleViewModel @Inject constructor( private val savedStateHandle: SavedStateHandle, private val repository: ExampleRepository ) : ViewModel() { …
Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216
9
votes
1 answer

Duplicate bindings with TestInstallIn for instrumented test

I'm using Hilt to inject some dependencies like so: @Module @InstallIn(SingletonComponent::class) object SomethingModule { @Provides fun provideSomething(@ApplicationContext context: Context): Something { //return RealSomething …
alisonthemonster
  • 1,095
  • 1
  • 11
  • 28
9
votes
2 answers

Android HILT SingletonComponent vs the GoF Singleton instance design pattern

In an Android project, there is a facade implemented as the singleton. I thought it is an better idea converting it to DI with HILT SingletonComponent. @Module @InstallIn(SingletonComponent::class) object MyManagerModule { @Provides fun…
Sean
  • 2,967
  • 2
  • 29
  • 39
9
votes
5 answers

@InstallIn can only be used on @Module or @EntryPoint classes

I am new at the dependency injection on Android. I am using Dagger-Hilt and in AppModule class that I generated for the DB providers I got an error and the project doesn't compile. The error is @InstallIn can only be used on @Module or @EntryPoint…
enesigneci
  • 301
  • 1
  • 4
  • 13
9
votes
1 answer

How to access injected properties in attachBaseContext using Hilt?

For the sake of changing application's default Locale, I have to get access of my WrapContext class in attachBaseContext method inside the Activity: @AndroidEntryPoint class MainActivity : AppCompatActivity() { @Inject lateinit var wrapper:…
9
votes
1 answer

@dagger.hilt.android.qualifiers.ApplicationContext android.content.Context cannot be provided without an @Provides-annotated method

I'm doing a relativity simple implementation of Hilt. I've set it up and I can't seem to get around this error: [Dagger/MissingBinding] @dagger.hilt.android.qualifiers.ApplicationContext android.content.Context cannot be provided without an…
Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106
9
votes
2 answers

How to pass arguments to Hilt module?

I started to migrate Dagger application to Hilt, first I'm converting AppComponent to Hilt auto-generated ApplicationComponent. Therefore I've added @InstallIn(ApplicationComponent::class) annotation to each module related to this component. Now I…
Micer
  • 8,731
  • 3
  • 79
  • 73
8
votes
1 answer

Hilt Inject field into any class with no scope

Suppose that I have a class A class A () I want to inject an instance of A as a field into class B and let Hilt or Dagger to handle it. Class B { @Inject lateinit var a: A } Let say class B is a plain class, has no context, e.g viewmodel or…
T D Nguyen
  • 7,054
  • 4
  • 51
  • 71