Questions tagged [dagger-2]

Dagger 2 is a dependency injection framework for Java and Android. It implements the full stack with generated code

Dagger 2 is a compile-time dependency injection framework for and .

It uses code generation and compile-time validation taking the approach started with Dagger 1 to it's ultimate conclusion. Dagger 2 eliminates all reflection and improves code clarity by removing the traditional ObjectGraph/Injector in favor of user-specified @Component interfaces. Dagger 2 implements the full stack with generated code.

Useful Links

3161 questions
1
vote
0 answers

Why I need HasAndroidInjection to inject an inner Fragment?

I have an Activity called Activity1, then inside has a Fragment1 all have the @ContributeAndroidInjection and then if my Activity2 wants to inject Fragment1 Why I need to implement HasAndroidInjector and do the @Inject lateinit var androidInjector:…
StuartDTO
  • 783
  • 7
  • 26
  • 72
1
vote
1 answer

ClassNotFoundException on Worker class

I'm getting a lot of strange errors in production, that only happens to a few users, so 99% of users are okay. java.lang.Error: java.lang.ClassNotFoundException: com.packagename.core.Translations.TranslationWorker at…
Syntey
  • 147
  • 1
  • 15
1
vote
1 answer

How to solve missing InjectedFieldSignature Error implementing Dagger 2 in android?

I have implemented dependency injection in android before using dagger 2 but, recently, I have tried to use it in a new project but I get the following error: error: cannot find symbol import dagger.internal.InjectedFieldSignature; ^ symbol: …
Vicki Mes
  • 35
  • 9
1
vote
0 answers

Trying to fetch data while using room and networkboundresource class

I'm trying to fetch data from Tmdb and i'm using room , dagger2 and networkboundresource class but the data not displayed and the logcat didn't show me any error .. i think i'm calling the wrong method in viewmodel or what fun loadMovies(page: Int…
1
vote
1 answer

Unresolved reference: DaggerAppComponent after converting to Kotlin

I am converting an old codebase from Java to Kotlin, but I'm struggling with implementing the Dagger components. I have tried multiple solutions and imports, however Android Studio refuses to recognize DaggerAppComponent. This is my…
Alex Petev
  • 501
  • 5
  • 19
1
vote
0 answers

Hilt particular feature dependency

@Module(includes = [AuthModule.ViewModel::class, AuthModule.UseCase::class, AuthModule.Api::class, AuthModule.Repository::class, AuthModule.Interactor::class]) @InstallIn(ActivityComponent::class) class AuthModule { @Module …
Avais Shaikh
  • 151
  • 2
  • 4
1
vote
1 answer

Compile time error with Dagger Hilt Android: okhttp3.Interceptor cannot be provided without an @Provides-annotated method

I am learning dagger hilt without learning dagger2 and came up with an error which I can't find a solution. I have two methods provideLoggingInterceptor() and provideHeaderInterceptor() which returns the same Interceptor object so I added a @Named()…
Vivek Singh
  • 1,142
  • 14
  • 32
1
vote
0 answers

Testing Multi module dagger dependency in Unit Test Android

This is my Activity where my AppModule Test activity is calling Another module's dependency. class MyPageActivityTest { lateinit var myPageActivity: MyPageActivity @RelaxedMockK lateinit var context: Context lateinit var mBTest:…
Reshma
  • 1,449
  • 2
  • 10
  • 17
1
vote
1 answer

Hilt in feature modules

I added a dynamic feature module to the android project. I know that hilt does not support this type of modules. I found a workaround for this problem in google documentation. Hilt in feature modules I have a project structure as below App - main…
1
vote
0 answers

error: @Subcomponent.Factory method has parameters for modules or subcomponents that aren't required

So i was build a dagger app and was trying get rid of subcomponent using @ContributesAndroidInjector But, its throwing error: @Subcomponent.Factory method has parameters for modules or subcomponents that aren't required, I tried everything and…
bv akhil
  • 136
  • 6
1
vote
2 answers

Android: Where to put functions that multiple fragments share

I have three fragments and all of them have two functions which are EXACTLY THE SAME. My problem is that I (obviously) don't want to copy the same two functions over and over again and put it in the fragments. Ain't there a way to put these…
Andrew
  • 4,264
  • 1
  • 21
  • 65
1
vote
1 answer

Is it possible to nullify dagger application component and create a new dagger application component in android

I have a feature where I need to have different Room Databases for different users. I am using Dagger 2 for creating Room Database. My Application Component creates one room database. When user switches to another user I want to create new Room…
keshav kowshik
  • 2,354
  • 4
  • 22
  • 45
1
vote
0 answers

Sharing data across fragments in a single flow using Android Dagger Hilt

TL;DR: How to share data in a single flow using Dagger/Hilt Component but not shared view model? I am trying to adopt the approach shown in Android docs, which uses Manual Dependency Injection to Dagger-Hilt Dependency Injection, using…
PGliw
  • 311
  • 4
  • 9
1
vote
1 answer

Inject Application Context in Repository with Dagger 2

I used the Dagger 2.17 to get the application context in the repository to access the resources: ContextInjection.kt: @Module class ContextModule(private val context: Context) { @Singleton @Provides fun providesContext(): Context { …
1
vote
1 answer

Framents in viewpager displaying the same content

I have pondered on this for days now, I need help. I have 2 fragments in a viewpager. They are both showing the same values despite feeding them with different data. Link to image Fragment A has a spinner dropdown of countries same as Fragment B.…