How to use dagger in a android library project

In case someone using Dagger 2 gets here, this is the way I’ve done in my App: In the library module I’ve created the following Module and Component: @Module public class ModuleUtil { @Provides public RestTemplate provideRestTemplate() { return new RestTemplate(); } } @Singleton @Component( modules = { ModuleUtil.class }) public interface MainComponent { void … Read more

Dagger 2 – what is the purpose of a @Singleton annotation class

@Singleton (and any other scope annotation) makes your class a single instance in your dependencies graph (it means that this instance will be “singleton” as long as Component object exists). In short – everytime you’re injecting @Singleton annotated class (with @Inject annotation) it will be the same instance as long as you inject it from … Read more

Does “Avoid dependency injection frameworks” in the Android Memory Guide apply to Dagger as well?

This recommendation does not apply equally to all dependency injection frameworks. ..frameworks [that work like Guice] tend to perform a lot of process initialization by scanning your code for annotations, which can require significant amounts of your code to be mapped into RAM even though you don’t need it.. Thus, if using a DI/IoC framework … Read more

Dagger and Butter Knife vs. Android Annotations

AndroidAnnotations uses compile time annotation processing. It generates a sub class with an underscore apppended to the original name (MyActivity_ generated from MyActivity). So to have it work you always have to use the generated class for references instead of your original class. It has a very rich feature set, see the list of available … Read more

How do you override a module/dependency in a unit test with Dagger 2.0?

Probably this is more a workaround that proper support for test module overriding, but it allows to override production modules with test one. The code snippets below shows simple case when you have just one component and one module, but this should work for any scenario. It requires a lot of boilerplate and code repetition … Read more

Kotlin Error: Dagger does not support injection into private fields

You have mistake here: @Inject internal var mSharedPreferences: SharedPreferences? = null This looks like you added @Inject annotation to the KotlinFragment class Please change it to this and it will work: var mSharedPreferences: SharedPreferences? = null @Inject set Here is the link to the documentation: https://kotlinlang.org/docs/reference/annotations.html

Difference between Dagger and ButterKnife Android

ButterKnife is targeted to inject views only. Non-activity injection just means that you can provide your own view root to inject views from (like with manually inflated views, etc.). Dagger is a bit more complicated. It can inject anything you want as long as you specified Module – class which satisfies those dependencies (alternatively you … Read more

Dagger 2 component not generated

When developing on Kotlin, you should add the following lines next to their annotationProcessor counterparts: kapt ‘com.google.dagger:dagger-android-processor:2.15’ kapt ‘com.google.dagger:dagger-compiler:2.15’ and add apply plugin: ‘kotlin-kapt’ at the start of the same file. That section looks like this for me: apply plugin: ‘com.android.application’ apply plugin: ‘kotlin-android’ apply plugin: ‘kotlin-kapt’ // <- Add this line apply plugin: ‘io.fabric’

Dagger: IllegalArgumentException: No injector factory bound for Class

I believe you have forgot to put @ContributesAndroidInjector annotation: @Module public abstract class ActivityModule { @ContributesAndroidInjector abstract ProductListActivity contributeProductListActivity(); @ContributesAndroidInjector abstract ProductDetailsActivity contributeProductDetailsActivity(); } And include ViewModelModule within AppModule: @Module(includes = ViewModelModule.class) class AppModule { … } See this code that you have wrote: @Provides @Singleton ProductListRepository provideProductListRepository(ProductListRepository repository) { return repository; } What do … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)