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?
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.
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.
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.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With