Error: cannot find symbol variable DaggerAppComponent

后端 未结 8 1799
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-19 08:50

While trying to integrate latest Dagger 2 version, I am facing problem of Dagger auto generation. Dagger is not auto generating DaggerAppComponent in spite of several Rebuilds a

8条回答
  •  天命终不由人
    2021-02-19 09:33

    Chenge code to this,

     private void initAppComponent()
    {
    /*    DaggerAppComponent.builder()
                        .appModule(new AppModule(this))
                        .build();*/
            appComponent = DaggerAppComponent.builder()
                    .appModule(new AppModule(this))
                    .build();
            appComponent .inject(this)
        }
    

    Other things are

    @Singleton
    @Component(modules = AppModule.class)
    public interface AppComponent
    {
        void inject(BaseApplication application);
    }
    

    Why you need to inject same class where a component is built you can easily get context and application on Application class. Dagger can help you to find a dependent class.

提交回复
热议问题