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

Cannot inject object provided in AppModule to Activity in a dynamic feature module with Dagger2

With the set up below i'm not be able to inject a Singleton object to a Activity inside a dynamic feature module. I can inject to a subComponent, MainActivity, but not to an Activity that's in dynamic feature module. @Component(modules =…
Thracian
  • 43,021
  • 16
  • 133
  • 222
1
vote
1 answer

Field injection in kotlin is always null

I am trying to do a field injection in a non Activity class, but I am always getting that the field has not been initialized/null. I have read Can I use Dagger 2's field injection in Kotlin?, also Dagger 2 on Android @Singleton annotated class not…
Tony
  • 159
  • 1
  • 11
1
vote
0 answers

how to start an activity from UncaughtExceptionHandler in DaggerApplication

I'm facing a similar scenario like this with the same strange behaviour: The intent will not fire, the crash dialog won't be showed either and the app closes by itself after crashing. Logcat shows the error like this: E/InputEventSender: Exception…
1
vote
0 answers

NoSuchFieldError for a private field in a class

I am facing an issue where my android code is throwing NoSuchFieldError only on some Samsung devices. From what I understand, NoSuchFieldError usually occurs due to usage of different library version at compile and run time. However, in this case,…
icoder
  • 61
  • 2
  • 8
1
vote
0 answers

Android Viewmodel savestate using dagger2

I am using ViewModel savestate handle in my app, I inject ViewModel using the dagger, So I used AssistInject to inject SaveStateHandle in to viewmodel. Everything works fine for me, But one thing I need to know is that I need to pass the bundle…
Stack
  • 1,164
  • 1
  • 13
  • 26
1
vote
0 answers

Dagger MutableLiveData Identifiers

I'm using Dagger Module to Inject MutableLiveData into my project The problem is using different identifier for each MutableLiveData provider that returns the same object @Module public class LiveDataModule { @Provides public…
1
vote
1 answer

Dagger gives error on migrating from version 11 to 12 - Android Java

The following gives error on upgrading com.google.dagger:dagger:2.11 to com.google.dagger:dagger:2.12. The same error comes even if we upgrade firebase. @Provides @ActivityScope public DashboardPresenter provideDashboardPresenter( final…
Sindhu Arju
  • 438
  • 1
  • 5
  • 15
1
vote
0 answers

Dagger2: How to inject a member variable during polymorphism?

public class A { protected B mB; public A() { createB(); } public void createB() { mB = new B(); } } public class ChildA extends A { public ChildA() { super(); } public void createB() { …
William Du
  • 11
  • 2
1
vote
1 answer

Dagger2 dependency Cycle by Using @Binds and @Inject fields

I am getting a dependency cycle whenever I try to use a subcomponent with binding objects. I have an app scope and an activity scope. At the app scope I create my web service then when the activity opens I want to create a storage object,…
Zachary Sweigart
  • 1,051
  • 9
  • 23
1
vote
0 answers

Why does kotlin not allows to define property or annotate in the secondary constructor?

I am using dagger dependency injection in my application,I use Qualifiers to inject my class with secondary constructor with Qualifier, But kotlin shows me compile time error says This annotation is not applicable to target value…
Stack
  • 1,164
  • 1
  • 13
  • 26
1
vote
1 answer

Dagger2 + ActivityInjection + AndroidXTest/Espresso/RoboElectric in library project

I am working on android library module and I want to test the standalone activity in my module. I was following the article https://medium.com/androiddevelopers/write-once-run-everywhere-tests-on-android-88adb2ba20c5 to use roboelectric and androidx…
1
vote
0 answers

Unable to use ContributesAndroidInjector with Fragments when using DynamicFeatureModules

I've been trying to inject dependencies for my fragments using ContributesAndroidInjctor instead of creating a subcomponent but it throws an exception, java.lang.IllegalArgumentException: No injector factory bound for Class Here is…
1
vote
1 answer

Dagger 2 providing different interface implementation is causing errors

I'm new in Dagger dependency injection. I have this interface implemented in two different classes: interface TaskCardContract { interface View{ fun setDescription(description: String) fun setSubTitle(subTitle: String) …
learner
  • 1,311
  • 3
  • 18
  • 39
1
vote
1 answer

Dagger multibinding with a custom qualifier

I have the following interface called SettingHandler that is responsible for handling events related to a particular setting inside the Android app. interface SettingHandler { fun onHandleEvent(event: SettingEvent) fun…
1
vote
0 answers

Retrofit interceptor with dagger2 timeout exception

I have an interceptor which works fine when i turn off internet it throw's the exception as expected but the problem occur when i turn on internet back again i get timeout exception. AppModule.java @Singleton @Provides Retrofit…
Sarvesh Chavan
  • 73
  • 1
  • 3
  • 7