FAQ Database Discussion Community


Java annotation processing for Android unit testing (w/ Dagger)

android,unit-testing,android-studio,gradle,dagger
I am attempting to set up Android unit tests in Android Studio 1.0 using DI from Dagger version 1.2.2. Whenever I run my tests and I attempt to instantiate an ObjectGraph with my test module, I get the following error/stacktrace: java.lang.IllegalStateException: Module adapter for class java.util.Arrays$ArrayList could not be loaded....

Dagger 2 error: dependency “cannot be provided without an @Inject constructor” while it actually annotated with @Inject

android,dagger,dagger-2
I've started using Dagger 2 and faced strange issue that looks like a bug to me. I have 3 modules, that are composed into one subcomponent, which in turn extends/pluses higher level component. Subcomponent is pretty simple: just combination of modules and a single injection point: @Singleton @Subcomponent( modules =...

Can I use Dagger 2 in a Java EE project?

java,jsf,dependency-injection,dagger,jsr330
My boss has researched about Dagger 2 and he would like me to use this in my JSF projects. I have seen many references about Dagger 2 and Android. But, is it possible to use this framework in a JSF web application?

Annotation processing for Dagger with Maven

java,maven,annotations,dagger
I am setuping Maven for project that uses Dagger, but I can't find good guide about annotation processing setup for maven-processor-plugin Here is part of my pom.xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.bsc.maven</groupId>...

Dagger2 Component as Static Global Variable

android,dagger,dagger-2
My Android app has multiple activities. The MainActivity constructs a Dagger2 component in its onCreate() method and assigns it to a static variable so any class can call the static method MainActivity.getDaggerComponent() to then inject itself with dependencies. The problem I'm discovering is that when I start up my VideoPlayerActivity,...

Dagger: need help in understanding

android,dagger
I have some misunderstandings of the way that dagger works: There are only two ways to satisfy dependency: whether the @Provide method returns the instance, or the class should have @Singleton annotation, is that right? Must the class constructor have @Inject annotation in the latter case? As I see, the...

Dagger 2 Third part Injection Android

android,dependency-injection,dagger
Hi im trying to figure out how to do a clean third party injection. I want to inject Otto bus properly into my services and activities. Iv seen that you can use inject on constructor, but since I dont have any constructor with Android, i wonder how I can then...

Module per Fragment / Activity in Dagger

android,dagger
I'm wondering if it is better to have a Module per Activity than a Module per Fragment? In one of my projects, I have an architecture to have a Module per Fragment because I use Activity just to hold and swap Fragments and nothing more. I only create Presenters and...

Dagger inject onStart

android,android-activity,android-lifecycle,dagger
Research: Couldn't find anything similar. I have a Singletonand I inject it into my SecondActivity in the Constructor using InjectorUtil.inject(this);. I then call mySingleton.getPersonCount() and it gives me the count. My problem is that when I leave the app and return to it. From my understanding causing the onStop() then...

Context cannot be provided without an @Provides-annotated method, but it is?

android,dagger,dagger-2
I have the following simple module: @Module public class ApplicationModule { private CustomApplication customApplication; public ApplicationModule(CustomApplication customApplication) { this.customApplication = customApplication; } @Provides @Singleton CustomApplication provideCustomApplication() { return this.customApplication; } @Provides @Singleton @ForApplication Context provideApplicationContext() { return this.customApplication; } } And the respective simple component: @Singleton @Component( modules = ApplicationModule.class...

How do make Dagger optional when buildling an SDK in Android/Java?

android,sdk,dagger
I am an SDK that will be public for other developers. I have build my SDK using Dagger thus far, but I wouldn't want developers to rely on Dagger when using the SDK. Is there a way to set the @Inject dependencies based on whether dagger has been enabled or...

Injecting Generics in Dagger

android,mvp,dagger
Is it possible in Dagger to do something like the following: public abstract class Presenter<T extends BaseView> { @Inject T mView; public void showLoadingIndicator() { mView.showLoading(); } } (example module) public class MyModule { private MyView mView; //extends BaseView public MyModule(MyView view) { mView = view; } @Provides public BaseView...