0

I have abstract FirstClass, and his child class SecondClass In second class I have dagger inject:

component.inject(this);

But _MembersInjector generate for this two classes — FirstClass_MembersInjector and SecondClass_MembersInjector

How can I exclude FirstClass_MembersInjector from my build?

winston
  • 875
  • 1
  • 8
  • 15
  • 1
    Why do you need that? What is your use-case? – azizbekian Aug 01 '17 at 08:45
  • I simplify my example, but at all looks like this: i have core library, two component libraries which use core lib, and big project which use this libs and core. Dagger generate MembersInjector for class from core in two libraries and gives me duplicate entry exception in main project @azizbekian – winston Aug 01 '17 at 09:00
  • Can you please delete or merge your old similar (duplicate) question - https://stackoverflow.com/q/45416388/5241933 – David Rawson Aug 01 '17 at 09:32
  • @DavidRawson It's visually similar questions, but it's about different siolutions – winston Aug 01 '17 at 12:38

1 Answers1

0

Assuming you have something like:

class FirstClass {

    @Inject Integer firstClassField;

}

then:

class SecondClass extends FirstClass {

    @Inject String secondClassField;

    void injectMembers() {
        DaggerComponent.builder().build().inject(this);
    }
}

Dagger 2 generates members injectors for all classes with @Inject annotated fields i.e., candidates for property injection. This is regardless of whether you are actually requesting injection for that class somewhere in your code or not.

In the contrived example above, the FirstClass_MembersInjector will be generated even though it is not used in the generated Dagger Component.

The solution to your problem probably lies with better organisation your project rather than trying to configure unusual behaviour for Dagger 2.

David Rawson
  • 20,912
  • 7
  • 88
  • 124
  • it's almost like my case, but there is one difference. In my case there is another one class in the hierarchy of inheritance between `FirstClass` and `SecondClass` without any injectable members. I'll call it `FirstAndHalfClass`. And for this class I don't want to have a `_MembersInjector` – winston Aug 01 '17 at 09:07
  • @winston I don't think preventing the generation of the `_MembersInjector` is the answer to that problem - it sounds like it is better to try and refactor and rename – David Rawson Aug 01 '17 at 09:10