Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating a MembersInjector for [Class]. Prefer to run the dagger processor over that class instead

I have these warnings and I don't understand what they mean. Can someone point me to something?

For classes I inject into (where there is a component.inject(this) statement)

Note: Generating a MembersInjector for [class] Prefer to run the dagger processor over that class instead.

For object I am injecting (constuctor annotated with @Inject)

Note: Generating a Provider for [class]. Prefer to run the dagger processor over that class instead.
like image 836
znat Avatar asked May 25 '16 12:05

znat


People also ask

What is Dagger used for in java?

Dagger generates code similar to what you would have written manually. Internally, Dagger creates a graph of objects that it can reference to find the way to provide an instance of a class. For every class in the graph, Dagger generates a factory-type class that it uses internally to get instances of that type.

How does Dagger 2 work?

Dagger 2 is the first to implement the full stack with generated code. The guiding principle is to generate code that mimics the code that a user might have hand-written to ensure that dependency injection is as simple, traceable and performant as it can be.

What is Dagger Inject?

Dagger is a fully static, compile-time dependency injection framework for Java, Kotlin, and Android. It is an adaptation of an earlier version created by Square and now maintained by Google.

What is a Dagger module?

Apart from the @Inject annotation, there's another way to tell Dagger how to provide an instance of a class: the information inside Dagger modules. A Dagger module is a class that is annotated with @Module . There, you can define dependencies with the @Provides annotation. Kotlin Java.


1 Answers

When Dagger's annotation processor runs, it generates two types of classes:

  1. Implementations of @Component interfaces
  2. Provider and MembersInjector implementations for each @Inject'd type.

While it's generating the @Component interface implementation, it connects each of the Provider and MembersInjector implementations according to how your modules were configured. If your component or any of the modules therein refer to an @Inject'd type that was compiled without the Dagger processor it will still generate the Provider or MembersInjector, but once for each component rather than once for the @Inject'd class.

This isn't really a problem (hence not a warning or error), but it does mean that can potentially have the Dagger processor generate the same classes many times for a single application. It might slow down compilation if and take up a bit more bytecode if it really gets out of hand.

The easy fix is just to make sure that you're running the Dagger annotation processor when you compile your @Inject'd types as well as your components.

like image 83
gk5885 Avatar answered Sep 19 '22 05:09

gk5885