Include AAR dependency in Android Library Project

前端 未结 4 1912
北荒
北荒 2021-02-06 10:16

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 a

相关标签:
4条回答
  • 2021-02-06 10:18

    I wanted to add my AAR file to my library project. I had to add this to the gradle of my library project

    implementation(files("libs/sublibrary.aar"))
    

    where my 'libs' folder is located at myLibraryName/libs.

    I also had to add the following to the gradle of my Main project

    implementation(files("../myLibraryName/libs/sublibrary.aar"))
    

    Then I synced and it worked.

    0 讨论(0)
  • 2021-02-06 10:21

    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')

    0 讨论(0)
  • 2021-02-06 10:31

    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.

    0 讨论(0)
  • 2021-02-06 10:35

    In case the answer by user1033552 doesn't work. In my case, it didn't work.

    Below steps worked for me.

    1. Right click project -> New -> Module -> Import aar package -> select file and import it.
    2. In settings.gradle, Make dependent is after dependency.For example include ':imported-aar', ':your-library', ':app'
    3. Now build.gradle of your-library add compile project(':imported-aar')
    0 讨论(0)
提交回复
热议问题