[Android] Local jars not packaged into .aar

I’m trying to create a task that downloads the dependencies as jars, puts them into ‘libs’ and then builds the .aar so it includes its dependencies in itself. What I have is

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

task cleanLibsDir(type: Delete) {
      delete fileTree(dir: "libs")

tasks.whenTaskAdded { addedTask ->
    if (addedTask.name == 'assembleRelease') {
        task archiveSdk(dependsOn: [clean, copyLibs, assembleRelease, cleanLibsDir])
        clean.mustRunAfter copyLibs
        assembleRelease.mustRunAfter clean
        cleanLibsDir.mustRunAfter assembleRelease

The first two work correctly, but while archiveSdk appears to do what it’s meant to (download jars, build, clean up), the downloaded jars get completely ignored. If I run copyLibs first then archiveSdk (so the jars are already in place), they DO get packaged correctly into the aar, so I guess the android plugin has already decided what files go into the artifact by the time my copy task is executed.

I tried forcing the preBuild task of android to ‘mustRunAfter’ copyLibs, but even that hasn’t helped. How can I ensure that my jars are existant early enough for the ‘assembleRelease’ task?

Any suggestions?