0

I am working with an ndk project using gradle-experimental. I have a "prebuilt" library that is really a library I generate with a shell call in a gradle task. I am trying to make it very easy for this project to run out of the box, so I need to be able to run this buildTask before gradle builds. I have looked into preBuild.dependsOn ..., but unfortunately, that is not supported in experimental. Any ideas? I currently have a .sh file that runs it, but I'm trying to get away from it.

Edit: Not duplicate because gradle-experimental doesn't support preBuild as I already stated.

iHowell
  • 2,263
  • 1
  • 25
  • 49
  • Possible duplicate of [execute task before android gradle build?](http://stackoverflow.com/questions/18532415/execute-task-before-android-gradle-build) – Bertrand Martel Jul 27 '16 at 19:01
  • Except this is in gradle-experimental. Please read the differences and what I wrote. – iHowell Jul 27 '16 at 19:02

1 Answers1

-1

Assumptions:

  • NDK moduleName is foo
  • Supported ABI is armeabi
  • Variants are debug and release

You'll have to create a combination for every variant and ABI you added to the abiFilters.

Create a RuleSource class in build.gradle

class FooRuleSource extends RuleSource {

    @Mutate
    void validatePreCompileFooDebugEnvironmentArmeabi(
        @Path('tasks.compileFooArmeabiDebugSharedLibraryFooMainCpp') Task compileTask) {
        validateEnvironment(compileTask)
    }

    @Mutate
    void validatePreCompileFooReleaseEnvironmentArmeabi(
        @Path('tasks.compileFooArmeabiReleaseSharedLibraryFooMainCpp') Task compileTask) {
        validateEnvironment(compileTask)
    }

    private void validateEnvironment(compileTask) {
        compileTask.dependsOn("desiredTask")
    }

}

Create the task in your build.gradle:

task desiredTask(type:Exec){
    commandLine 'echo', 'hi'
} 
Thom
  • 19
  • 4