Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Gradle build and circular dependency

I have an Android project in IntelliJ IDEA. It consists of two modules: app and library. App depends on library and library depends on app (Yes, it's not good, but I have what I have and can't change this). IDEA in project settings warn me about circular dependencies, but project builds correctly. Project structure looks like this:

project
|__app
|    |__src
|    |__build.gradle
|__libarary
|    |__src
|    |__build.gradle
|__build.gradle
|__settings.gradle

Now I'm trying to migrate to new Android build system based on Gradle and have a trouble here. In my build.gradle from app module I add dependency on library

compile project(":library")

Also I tryed to add dependency in library on app like

compile project(":app")

But gets error from build system, when gradle trys to assemble library module:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
   > Module version project:app:unspecified depends on libraries but is not a library itself

What I can do with this without changing project structure

like image 421
Dmitriy Tarasov Avatar asked Aug 02 '13 14:08

Dmitriy Tarasov


People also ask

What is circular dependency in Android?

In software engineering, a circular dependency is a relation between two or more modules which either directly or indirectly depend on each other to function properly. Such modules are also known as mutually recursive.

How do I fix circular dependency error?

Or in other words, the cell that the formula is entered in, is within the range that the formula refers to. This causes a circular dependency error. What is this? To fix this error, simply add the tab name to the references in the filter formula.

How do you avoid circular dependencies?

Avoiding circular dependencies by refactoring Circular dependencies create tight couplings between the classes or modules involved, which means both classes or modules have to be recompiled every time either of them is changed.

What is Gradle build in Android?

Android Studio uses Gradle, an advanced build toolkit, to automate and manage the build process, while allowing you to define flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app.


1 Answers

This parameters have changed.

You should now refactor:

In the library project use:

apply plugin: 'com.android.library'

In the app project use:

apply plugin: 'com.android.application'

like image 71
Lucas Avatar answered Oct 15 '22 14:10

Lucas