Search code examples
javaandroidstack-overflowdagger-2

stackoverflow when using two components Dagger2


I have two Components for Dagger :

@GithubListActivityScope
@Component(modules = { GithubListActivityModule.class, GlideActivityModule.class })
public interface GithubListActivityComponent {

GithubUserListAdapter githubUserListAdapter ( );
//RequestManager requestManager();
LinearLayoutManager linearLayoutManager();

}

Note : I have tried commenting and uncommenting RequestManager requestManager();in GithubListActivityComponent

I have another Component like this :

@Component(modules = { GithubApiServiceModule.class, GlideModule.class })
public interface GithubAppListComponent {

RequestManager getGlideRequestManager ( );

GithubAPIService getGitHubApiService ( );
}

Problem : -> When I delete the class file of GithubListActivityComponent or delete/comment the @Component Annotation the app runs fine BUT when I try building without deleting or commenting the @Component Annotation the file I get the following error :

Error:(7, 66) error: cannot find symbol class DaggerGithubAppListComponent

Error:Execution failed for task ':app:compileDebugJavaWithJavac'. java.lang.StackOverflowError

P.S. Oracle Jdk version -> 1.8.0_121


Solution

  • Remove Circular Dependency (A module should not include B Module if B Module includes A )

    How I solved my problem : the providers(Methods with @Provide) that were on GithubListActivityModule and depended on GlideActivityModule, I moved them into GlideActivityModule to remove the dependency.