问题
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?
回答1:
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')
回答2:
I had it working like this:
compile 'com.example.lib:lib_name:1.0.0@aar'
In this example lib_name:1.0.0.aar
is file name.
回答3:
In case the answer by user1033552 doesn't work. In my case, it didn't work.
Below steps worked for me.
- Right click project -> New -> Module -> Import aar package -> select file and import it.
- In settings.gradle, Make dependent is after dependency.For
example
include ':imported-aar', ':your-library', ':app'
- Now build.gradle of your-library add
compile project(':imported-aar')
来源:https://stackoverflow.com/questions/32071825/include-aar-dependency-in-android-library-project