Android Dagger 2:错误:[ComponentProcessor:MiscError]生成代码的循环依赖项
我正在从事一个项目,其中旧匕首是在代码库中实现的。今天,我尝试将dagger实现优化为dagger 2.2。正如您所知,google更新了dagger库以使该库易于在android中实现,有一些辅助类,如dagger活动、dagger应用程序和dagger片段类 我已经更新了库,但是我被错误缠住了Android Dagger 2:错误:[ComponentProcessor:MiscError]生成代码的循环依赖项,android,dagger-2,Android,Dagger 2,我正在从事一个项目,其中旧匕首是在代码库中实现的。今天,我尝试将dagger实现优化为dagger 2.2。正如您所知,google更新了dagger库以使该库易于在android中实现,有一些辅助类,如dagger活动、dagger应用程序和dagger片段类 我已经更新了库,但是我被错误缠住了 error: [ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to pro
error: [ComponentProcessor:MiscError]
dagger.internal.codegen.ComponentProcessor was unable to process this
interface because not all of its dependencies could be resolved. Check
for compilation errors or a circular dependency with generated code.
public abstract interface NewAppComponent extends
dagger.android.AndroidInjector<com.mallconnect.tdm.TDMApplication> {
我检查了一些StackOverflow帖子,但没有找到解决方案
我们如何追踪错误的来源?我已经解决了评论中建议的循环依赖性问题 如果不浏览
组件中包含的所有模块,就无法解决此问题
当我错误地浏览活动buildermodule
时,我提供的是AuthViewModel
而不是AuthViewModelModule
,在main片段buildermodule
中,我也在证明ViewModel
而不是contributeandroidjector
中的ViewModel模块无需查看组件中包含的所有模块
,即可寻址!我已经添加了ActivityBuilderModule所有其他模块都是相同的,它们使用的是旧的Daggerm。我的最佳猜测是AuthViewModel.class
导致了循环依赖关系。可能是因为它已被绑定到ViewModelModule
中。尝试从ActivityBuilderModule
中删除一次AuthViewModel.class
,然后重新生成noAuthViewModelModule.class
仅绑定在ActivityBuilderModule
@FazalHussain如果我认为这会导致问题,您是否使用BaseActivity
扩展了MainActivity
。
@Singleton
@Component(modules = [AndroidSupportInjectionModule::class,
ActivityBuilderModule::class,
AppModule::class,
RoomModule::class,
RetrofitModule::class,
MappedInModule::class,
ViewModelFactoryModule::class
])
interface NewAppComponent : AndroidInjector<TDMApplication> {
/**
* Session manager can be access any where in the application
*/
fun sessionManager(): SessionManager
@Component.Builder
interface Builder {
/**
* [BindsInstance] annotation is used for, if you want to bind particular object or instance
* of an object through the time of component construction
*
* @param application The application instance
*
* @return The Builder
*/
@BindsInstance
fun application(application: Application): Builder
/**
*
* @return the AppComponent
*/
fun build(): NewAppComponent
}
}
@Module
public abstract class ActivityBuilderModule {
@ContributesAndroidInjector(modules = {MainFragmentBuildersModule.class,
MainViewModelsModule.class})
abstract Main contributeMainActivity();
@ContributesAndroidInjector(modules = {AuthViewModel.class})
abstract BaseActivity contributeBaseActivity();
}