javaandroidandroid-studiobuild.gradlemobile-development

How to avoid error "Circular dependency between the following tasks:"?


In my app, build.gradle file i have added another module in the dependency like this

implementation project(':app1')

like wise, in that module also i have added my main module like below inorder to access some classes

implementation project(':app')

when i am trying to run my project it gives me an error like

Circular dependency between the following tasks:
:app:processDebugResources
\--- :app1:processDebugResources
     \--- :app:processDebugResources (*)

i don't have another option rather accessing classes between these two modules, because i want to access some classes which were in older version of the library but not included in the latest version, they have removed few classes in the latest version for some reason, is there an any method to avoid this Circular dependency problem or is there an any mothod of compiling both older and latest version in same module....

I have also read the answer of the following question in stack ( I am not able to import to class in different module in android studio)


Solution

  • Gradle, or for that matter, any dependency resolution libraries, or plugins, don't support circular dependencies, because that way, no one knows how to start resolving the dependencies

    By resolving the dependencies, in layman terms, I mean that, you wouldn't know which dependency to include in what module

    enter image description here

    As far as an alternative solution is concerned, you can create a module3, and make both the app module and your other module (module2) depend on this module3

    So, common code will be written in module3 and app and module2, can have build.gradle files as follows

    app level build.gradle file

    implementation project(':module3')
    

    module2 build.gradle file

    implementation project(':module3')