How to include JAR dependency into an AAR library

丶灬走出姿态 提交于 2019-11-26 22:11:10

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 dependencies
configurations {
    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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!