How to include JAR dependency into an AAR library How to include JAR dependency into an AAR library android android

How to include JAR dependency into an AAR library


You can add this task:

task copyLibs(type: Copy) {    from configurations.compile    into 'libs'}

Dependencies will be downloaded from your Nexus, but when you need package the library, execute this task first and jar files will be copied and included inside final aar.


By default, AAR does not include any dependencies. Solution mentioned by @Hector should work for gradle plugin < 3.0. For Gradle plugin 3.0+, try custom config as mentioned here.

android { ... }// Add a new configuration to hold your dependenciesconfigurations {    myConfig}dependencies {    ....    myConfig 'com.android.support:appcompat-v7:26.1.0'    myConfig 'com.android.support:support-v4:26.1.0'    ...}task copyLibs(type: Copy) {    from configurations.myConfig     into "libs"}


None of the suggestions helped me for Gradle 4.6, so I wasted the whole day inventing my own.

Eventually I found a good Gist and modified it for my version of Gradle:https://gist.github.com/stepio/824ef073447eb8d8d654f22d73f9f30b