Gradle multi-project dependency doesn't include

I’m trying to set up a Gradle build to build and include an NDK static library into an Android project, but can’t get the inclusion to work. I’m running Gradle 2.8 on a Linux system directly from the command line (AndroidStudio, Android SDK, and Android NDK are installed, but I’m not using them directly in the sample below). I’ve boiled down my issue to the following purely Gradle-based sample, and was hoping someone more versed in Gradle could show me the way.

Let’s say I have the following directory structure:

gradle_test
  mySubLibs
    common.gradle
    mySubA
      build.gradle
      settings.gradle
  myProjA
    common.gradle
    Projects
      Android
        build.gradle
        settings.gradle

My library sub projects are under the mySubLibs directory. I’ll have gradle_test be the root project directory to get around the fact that Gradle sucks with dealing with arbitrary paths (another gripe for another time).

First, I set up my library to build with “assembleRelease” and “clean” tasks. In reality it will call to command-line compilers to work, but for testing Gradle this simplification will do.

gradle_test/mySubLibs/common.gradle

buildscript {
}

task NDKBuildReleaseLib(type: Exec) {
  println "Running NDKBuildReleaseLib for " + rootProject.name
  commandLine 'touch', 'obj/local/myOutput.a'
}

task NDKBuildCleanLib(type: Exec) {
  println "Running NDKBuildCleanLib for " + rootProject.name
  commandLine 'rm', '../libs/myOutput.a', 'obj/local/myOutput.a'
}

task copyLibs(type:Copy) {
  from 'obj/local'
  into '../libs'
  include '*.a'
  outputs.upToDateWhen {false}
}
NDKBuildReleaseLib.finalizedBy copyLib

gradle_test/mySubLibs/mySubA/build.gradle

apply from: '../common.gradle'
configurations.create('default')

allprojects {
  task assembleRelease(dependsOn: NDKBuildReleaseLib) << {}
  task clean(dependsOn: NDKBuildCleanLib) << {}
}

gradle_test/mySubLibs/mySubA/settings.gradle

rootProject.name = "mySubA"
include ':'

This works fine. I can call “gradle assembleRelease” from the mySubA directory, and it builds my library file (the build being simulated by running “touch” to create a file). Now let’s create a similar setup for the main project.

gradle_test/myProjA/common.gradle

buildscript {
}

task NDKBuildRelease(type: Exec) {
  println "Running NDKBuildRelease for " + rootProject.name
  commandLine 'touch', 'obj/local/myProjOutput.a'
}

task NDKBuildClean(type: Exec) {
  println "Running NDKBuildClean for " + rootProject.name
  commandLine 'rm', 'obj/local/myProjOutput.a'
}

gradle_test/myProjA/Projects/Android/build.gradle

apply from: '../../common.gradle'
configurations.create('default')

dependencies {
//  default project(':mySubLibs:mySubA')
}

allprojects {
  task assembleRelease(dependsOn: NDKBuildRelease) << {
      println "Assemble Release for " + project.name
    }

  task clean(dependsOn: NDKBuildClean) << {
      println "Clean for " + project.name
    }
}

gradle_test/myProjA/Projects/Android/settings.gradle

rootProject.projectDir = new File(settingsDir, '../../..')
rootProject.name = "myTestBase"

include ':'
include 'mySubLibs:mySubA'
include 'myProjA:Projects:Android'

This mostly works, except that it is not causing the sub project to build. So my questions are:

  1. How do I get the sub-project to build? If I uncomment the line above in the “dependencies” section, I get an undefined token error. Almost all samples dealing with dependencies use “compile” instead of “default” there, but since this example doesn’t have a compile configuration created by the java plugin inclusion, I can’t do that (nor did it work when I tried that). I know the sub project is being evaluated from “gradle --info”, but it doesn’t run.

  2. How would I specify an arbitrary task to build the sub-project? In the above examples, I’ve set both up to build off a task named “assembleRelease”. How could I call “assembleRelease” to build the project, but have a task called “buildMySubLib” called to build the library project?

The end goal is to have multiple library projects called to each build their own static library and copy it to a known common location, then for the main project to include all the static lib files from that common location in its own compile and link stage. It seems silly to have to set up a task for each library in the main project that uses an Exec task to recursively call the command line version of “gradle” for each library project.

Thanks for any insight. This seems like it should be a pretty common build scenario, but it is proving to be unfortunately difficult to set up.