Dagger 2: error: [ComponentProcessor:MiscError] circular dependency with generated code
Dagger 2: error: [ComponentProcessor:MiscError] circular dependency with generated code
我正在做一个项目,旧匕首是在代码库中实现的。今天,我尝试将 dagger 实现优化到 dagger 2.2。如您所知,google 更新了 Dagger 库,使库易于在 android 中实现,有一些帮助程序 类,如 Dagger Activity、Dagger 应用程序和 Dagger 片段 类.
我已经更新了库,但我卡在了
的错误上
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> {
NewAppComponent
@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
}
}
ActivityBuilderModule
@Module
public abstract class ActivityBuilderModule {
@ContributesAndroidInjector(modules = {MainFragmentBuildersModule.class,
MainViewModelsModule.class})
abstract Main contributeMainActivity();
@ContributesAndroidInjector(modules = {AuthViewModel.class})
abstract BaseActivity contributeBaseActivity();
}
我查了一些 Whosebug post 但我还没有找到解决方案
Dagger2 Circular Dependency Error
Dagger 2.15: Appcomponent - was unable to process this interface
我们如何追踪错误的根源?
我已经解决了评论中建议的循环依赖问题
The issue can't be addressed without going through all the modules that have been included in the component
!
当我错误地通过 ActivityBuilderModule
时,我提供了 AuthViewModel
而不是 AuthViewModelModule
并且在 MainFragmentBuilderModule
内部我也证明了 ViewModel
而不是ViewModelModule
在 ContributeAndroidInjector
对我来说,这是因为我有一个数据 class,其中未指定顶部的包名称,因此,当导入此数据 class 时,它正在导入作为
import DataClassName
而不是完整的 class 化名,因此,它导致了循环依赖性
我正在做一个项目,旧匕首是在代码库中实现的。今天,我尝试将 dagger 实现优化到 dagger 2.2。如您所知,google 更新了 Dagger 库,使库易于在 android 中实现,有一些帮助程序 类,如 Dagger Activity、Dagger 应用程序和 Dagger 片段 类.
我已经更新了库,但我卡在了
的错误上 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> {
NewAppComponent
@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
}
}
ActivityBuilderModule
@Module
public abstract class ActivityBuilderModule {
@ContributesAndroidInjector(modules = {MainFragmentBuildersModule.class,
MainViewModelsModule.class})
abstract Main contributeMainActivity();
@ContributesAndroidInjector(modules = {AuthViewModel.class})
abstract BaseActivity contributeBaseActivity();
}
我查了一些 Whosebug post 但我还没有找到解决方案
Dagger2 Circular Dependency Error
Dagger 2.15: Appcomponent - was unable to process this interface
我们如何追踪错误的根源?
我已经解决了评论中建议的循环依赖问题
The issue can't be addressed without going through all the modules that have been included in the
component
!
当我错误地通过 ActivityBuilderModule
时,我提供了 AuthViewModel
而不是 AuthViewModelModule
并且在 MainFragmentBuilderModule
内部我也证明了 ViewModel
而不是ViewModelModule
在 ContributeAndroidInjector
对我来说,这是因为我有一个数据 class,其中未指定顶部的包名称,因此,当导入此数据 class 时,它正在导入作为
import DataClassName
而不是完整的 class 化名,因此,它导致了循环依赖性