Questions tagged [dagger]

Dagger is a dependency injection library for Java and Android.

Dagger, by Square, is a fast dependency injection library for Java and Android. It is compatible with JSR 330. Dagger intentionally leaves out some features and imposes some restrictions in order to attain rapid startup times by eliminating slow runtime reflection, especially on Android.

Dagger 2 is a fork maintained by Google which eliminates reflection in the graph generation phase.

For instance, Dagger does not support the following:

  1. Method Injections.
  2. private and final field injections.

Useful Links

1471 questions
0
votes
1 answer

Is it a good practice to use @Inject for Android's Fragment on Dagger2?

I am using @ContributesAndroidInjector of Dagger 2.11. It works without problems with the following sources. @ActivityScope is also working. class MainActivity : AppCompatActivity(), HasFragmentInjector { @Inject lateinit var…
ko2ic
  • 1,977
  • 14
  • 20
0
votes
2 answers

Android How to add external dependency (context) to SubComponent builder in Dagger 2.1.0

I am using dependency injection according to google sample The only external dependency I can pass is through AppComponent builder @Singleton @Component(modules = { AndroidInjectionModule.class, AppModule.class, …
Malbac
  • 197
  • 1
  • 1
  • 12
0
votes
1 answer

Dagger component & subcomponents

I am trying to figure out how to use Dagger components/subcomponents. I know it is the older style of things but I have a legacy app that is using this Dagger structure and I'm using this sample project to better understand it. This sample app has…
Franc
  • 41
  • 1
  • 2
0
votes
1 answer

Dagger 2.12 and proguard issue

I have an error after switching from Dagger 2.5 to 2.12 when using proguard on my release build. DaggerGraph.java:662: error: cannot find symbol ReportingService_MembersInjector.injectA(instance, provideDataLayerProvider.get()); I have an Android…
Sebastian
  • 236
  • 1
  • 3
  • 6
0
votes
0 answers

Dagger2 Build issue- cannot be provided without an @Inject constructor or from an @Provides- or @Produces-annotated method

I am new to Dagger 2 and has been making some good progress until recently. I have a fragment CalculatorFragment which unloads all of the logic into it's Presenter class, which has an interface ViewOps as it's constructor that is already implemented…
jairrab
  • 3
  • 1
  • 2
0
votes
1 answer

Use provide gradle dependency in Android Unit Test

I'm trying to integrate Dagger 2 to be used in unit tests. Unfortunately whenever I run my test I get java.lang.NoClassDefFoundError: javax/inject/Provider. I have the javax dependency added in Gradle like this: depdencencies { ... provided…
dephinera
  • 3,703
  • 11
  • 41
  • 75
0
votes
1 answer

How to specify Scope for SubComponent when using @ContributesAndroidInjector

I'm trying to understand the new New Android Injector with Dagger 2 from from this blog post. I understood the concept of @ContributesAndroidInjector, and how it avoids repetition of code as described in the blog UI…
user4260260
0
votes
1 answer

Dagger 2.11 [dagger.android.AndroidInjector.inject(T)] Found a dependency cycle

I am new to Dagger and learning implementation of Dagger 2.11 in an android application. I followed some tutorials and created a sample project. But I am getting this error : Error:(19, 8) error: [dagger.android.AndroidInjector.inject(T)] Found a…
Sar
  • 550
  • 4
  • 18
0
votes
1 answer

Dagger2 Component not generated

I'm trying to set up a project with Dagger. Right now when I build,none of the Dagger* classes are generated for the Components. Heres's my build.gradle config: dependencies = [ annotationProcessor 'com.google.dagger:dagger-compiler:2.11' …
warpath
  • 11
  • 4
0
votes
0 answers

ERROR: Tag Mismatch while Gradle build when adding Dagger 2(v2.11)

I'm getting TAG MISMATCH Error when adding Dagger 2 (v2.11) dependencies in app level build.gradle file. Searched a lot on Google but not getting the reason of this error. Anybody have idea about this problem?? This is dependencies in my app-level…
raghav_si
  • 185
  • 1
  • 15
0
votes
0 answers

Make a UserScope with Dagger2 that lives for multiple activities and fragments

I want to make a UserScope with Dagger 2 that provides a User for several Activities. When the User log-in, Dagger inject the User to these activities, and once the User log-out, the instance must be null until the next log-in. this is what i did so…
Fakher
  • 2,098
  • 3
  • 29
  • 45
0
votes
1 answer

Passing object to module with new Android injection

I'm using the new Android injection from dagger 2.11, and i have this simple module : @Module public class MyModule{ @MyScope @Provides SomeClass provideSomeClass(Context context){ return new SomeClass(context); } } as you can see i need to…
Mahdi Nouri
  • 1,391
  • 14
  • 29
0
votes
3 answers

How can i inject object into presenter in android kotlin MVP mosby app with dagger

I am trying to get dagger working in my application. After creating Module Component and MyApp i can use dagger to inject database service into view but i am having trouble doing same thing with presenter. Code: class MyApp : Application() { …
Piotr
  • 177
  • 1
  • 2
  • 12
0
votes
0 answers

Confusing error with Dagger 2 in Android

I've been trying to set up a dependency injection but there is something that I can't deal with. I almost understand Dagger expect some weird issues like this one. Here is the log error: e:…
Costular
  • 51
  • 2
  • 8
0
votes
1 answer

Dagger 2, MVVM: Adding a third tab and going back and forth crashes the app

I've been playing with this github repo: https://github.com/patloew/countries to learn DI, mvvm, realm, and all that good stuff. When I add a third tab in MainAdapter.java: @Override public Fragment getItem(int position) { switch…