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

前端 未结 2 1991
温柔的废话
温柔的废话 2021-02-12 20:58

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)

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-12 21:11

    I was getting this "Generating a MembersInjector for..." Dagger 2 warning when I had a superclass and subclass as follows...

    public abstract class BaseActivity extends Actvity {
    
        @Inject
        DependencyA dependencyA;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            ((MyApplication) getApplication()).getComponent().inject(this);
    }
    
    public class ConcreteActivity extends BaseActvity {
    
        @Inject
        DependencyB dependencyB;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            ((MyApplication) getApplication()).getComponent().inject(this);
        }
    }
    

    ... and my Component interface had two inject methods as follows...

    void inject(BaseActivity activity);
    void inject(ConcreteActivity activity);
    

    I removed the inject(BaseActivity activity) method from my Component interface and I removed the Component.inject(this) method call from the BaseActivity class. The injection in BaseActivity still works as expected when the subclass (ConcreteActivity) calls Component.inject(this) and I do not see the "Generating a MembersInjector for..." Dagger 2 warning anymore when I build the application.

提交回复
热议问题