Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include AAR dependency in Android Library Project

In my Android Studio Gradle project I use several libraries, whereas one library should use a local AAR file as dependency. I used the popular solution to include the AAR file as dependency into my library project:

flatDir {
    dirs 'libs'
}

compile(name: 'aar-library', ext: 'aar')

When I now try to sync I get the error message

Failed to resolve: dependency 'aar-library'

in my main project even though I'm not using / referencing the AAR file there. If I just copy the AAR file into the libs folder of my main project too it works. Any idea?

like image 696
user1033552 Avatar asked Aug 18 '15 11:08

user1033552


People also ask

Does AAR contain dependencies?

The aar file doesn't contain the transitive dependencies and doesn't have a pom file which describes the dependencies used by the module. It means that, if you are importing a aar file using a flatDir repository you have to specify the dependencies also in your project.

What is the difference between AAR and jar?

The main difference is aar is splitted inside android to jar. If your app will be used only in user app only in android studio then aar is preferred. If you are planning for app to communicate with c/c++ compiled lib.so file jar is preferred.

What is library dependency in Android?

Dependency types This declares a dependency on an Android library module named "mylibrary" (this name must match the library name defined with an include: in your settings. gradle file). When you build your app, the build system compiles the library module and packages the resulting compiled contents in the app.


1 Answers

Already found the solution. It looks like the AAR dependencies are all moved together, so the main project tries to resolve AAR dependency in its 'libs' directory, where it obviously does not exist. What you need to do is define more accurately where each module that depends on the library with the AAR file can find it relative to its path, e.g.

dirs project(':my-library-project').file('libs')

like image 56
user1033552 Avatar answered Oct 08 '22 21:10

user1033552