Connecting Copy output to Android input as dependency

Hi folks,

Gradle newbie here. I’m writing a script that involves copying a native library into a folder, which then gets included in an Android build task. However, I can’t get the Android build to recognize the copy task as a dependency. Here’s the gist of my script:

buildscript {
  repositories {
    google()
    jcenter()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:4.0.0'
  }
}

allprojects {
  repositories {
    google()
    jcenter()
  }
}

def copyLibraries = tasks.register("copyLibraries", Copy)

copyLibraries.configure {
  from(
    'sub/libAndroidTest.so',
  )
  into "${buildDir}/lib"
}

apply plugin: 'com.android.application'

android {
  compileSdkVersion 30
  buildToolsVersion '30.0.0'

  defaultConfig {
    applicationId 'com.kitware.cmaketest'
    minSdkVersion 16
    targetSdkVersion 30
  }

  sourceSets {
    main {
      manifest.srcFile 'AndroidManifest.xml'
      java.srcDirs = [
        'main/java',
      ]
      jniLibs.srcDirs = [
        copyLibraries.map { it.destinationDir }
      ]
    }
  }
}

As you can see, I am trying to get the jniLibs source set to recognize the Copy output as a dependency, following the Lazy Configuration guide, but it’s not taking the dependency. What am I doing wrong? (I would rather not explicitly use dependsOn().)