Gradle 3.0 above solution for dependency copying

Hi,

I am trying to build an android library (.aar) with gradle 3.1.1. Recently migrated from gradle 2.0 to this version. In the gradel there is a step to copy dependencies before archiving. The step to archive is found in the suggested solution in this post, https://stackoverflow.com/questions/33445270/how-to-include-jar-dependency-into-an-aar-library. But the solution does not work after gradle upgrade.

I am looking to get a solution as part of this post and help is much appreciated.

Feel free to reply here as well so the solution can be open to all who are suffering from the same.

To add more details

In my existing project, artifacts as .aar is getting pushed to artifactory. With that artifact I need to include dependent libraries classes that are used in the project. I currently have a solution as below to copy all compile dependencies.

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

With gradle 3.0 and above, compile is replaced and hence not able to find any compile configurations. This makes it ignore any dependencies to be included in aar.

I am looking for a solution that works similarly with implementation or api configurations.

I sent you this solution a while ago:

android.applicationVariants.all { variant ->
    task "copy${variant.name.capitalize()}Dependencies"(type: Copy) {
        def artifactType = Attribute.of("artifactType", String)
        from configurations."${variant.name}CompileClasspath".incoming
            .artifactView { attributes.attribute(artifactType, "jar") }.files
        into "libs"
    }
}

Can you please clarify what is not working for you there? You’ll of course have to adjust it to your specific use case, the above will just include all the jars, but you may want aars or something else. It will create a copy task per variant, but of course you could also easily refactor this to do one copy task for all variants. It really depends on what your requirements are.