简体   繁体   中英

Exclude generated by dagger2 class from apk

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?

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 ie, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM