Dagger not generating components for /test class

You need to add following to your build.gradle file for instrumentation test: androidTestApt ‘com.google.dagger:dagger-compiler:<version>’ or for JUnit test: testApt ‘com.google.dagger:dagger-compiler:<version>’ This is required to generate Dagger code for your test components. EDIT: If you are using jack tool chain then add following for android test: androidTestAnnotationProcessor ‘com.google.dagger:dagger-compiler:<version>’ for JUnit tests: testAnnotationProcessor ‘com.google.dagger:dagger-compiler:<version>’ EDIT: In case … Read more

Set dynamic base url using Retrofit 2.0 and Dagger 2

Support for this use-case was removed in Retrofit2. The recommendation is to use an OkHttp interceptor instead. HostSelectionInterceptor made by swankjesse import java.io.IOException; import okhttp3.HttpUrl; import okhttp3.Interceptor; import okhttp3.OkHttpClient; import okhttp3.Request; /** An interceptor that allows runtime changes to the URL hostname. */ public final class HostSelectionInterceptor implements Interceptor { private volatile String host; public … Read more

Why use/develop Guice, when You have Spring and Dagger? [closed]

It’s important to acknowledge that Dagger was created after Guice, by one of Guice’s creators (“Crazy Bob” Lee) who had moved to Square: Rod Johnson originally released Spring in October 2002 with his book Expert One-on-One J2EE Design and Development; Spring was then released publicly on the Apache license in June 2003 and as v1.0 … Read more

Dagger- Should we create each component and module for each Activity/ Fragment

Declaring a separate module for each Activity is not a good idea at all. Declaring separate component for each Activity is even worse. The reasoning behind this is very simple – you don’t really need all these module/components (as you have already seen by yourself). However, having just one component that is tied to Application‘s … Read more

How to set up DAGGER dependency injection from scratch in Android project?

Guide for Dagger 2.x (Revised Edition 6): The steps are the following: 1.) add Dagger to your build.gradle files: top level build.gradle: . // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath ‘com.android.tools.build:gradle:2.2.0’ classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8’ //added apt for source code generation … Read more

Error : Program type already present: android.support.design.widget.CoordinatorLayout$Behavior

It worked when I downgrade the support appcompat gradle dependency, like follwing : implementation ‘com.android.support:appcompat-v7:27.0.2’ previously it was implementation ‘com.android.support:appcompat-v7:27.1.0’ OR Also this can be fixed by just adding support design dependency of version 27.1.0 or above to your app level build.gradle as following : implementation ‘com.android.support:design:27.1.0’

What determines the lifecycle of a component (object graph) in Dagger 2?

As for your question What determines the lifecycle of a component (object graph) in Dagger 2? The short answer is you determine it. Your components can be given a scope, such as @Scope @Retention(RetentionPolicy.RUNTIME) public @interface ApplicationScope { } @Scope @Retention(RetentionPolicy.RUNTIME) public @interface ActivityScope { } These are useful for you for two things: Validation … Read more

Dagger 2 subcomponents vs component dependencies

Component dependencies – Use this when you want to keep two components independent. Subcomponents – Use this when you want to keep two components coupled. I will use the below example to explain Component dependencies and Subcomponents. Some points worth noticing about the example are: SomeClassA1 can be created without any dependency. ModuleA provides and … Read more