Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dagger 2: error: [ComponentProcessor:MiscError] circular dependency with generated code

I am working on a project where the old dagger is implemented in code-base. Today, I try to optimize the dagger implementation to dagger 2.2. As you know that google updated the dagger library to make the library easy to implement in android there are some helper classes like Dagger Activity, Dagger Application, and Dagger Fragment classes.

I have updated the library but I got stuck on the error saying that

 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();



}

I have checked some StackOverflow post but I have not found the solution

Dagger2 Circular Dependency Error

Dagger 2.15: Appcomponent - was unable to process this interface

How can we trace what is the origin of the error?

like image 518
Fazal Hussain Avatar asked Sep 13 '25 09:09

Fazal Hussain


1 Answers

For me this was because, I had a data class in which the package name at the top was not specified and so, when this data class was being imported, it was being imported as import DataClassName instead of full classified name and thus, it was resulting in circular dependency

like image 196
Sonu Sourav Avatar answered Sep 15 '25 00:09

Sonu Sourav