Vaggelis Larios
Vaggelis Larios

Reputation: 11

Generated code stays in build folder after Android Studio Build

I am using a gradle task to generate some code for my API and store this code into the build folder. When I am building my application the process deletes the build folder.

Is there a way to call my code generation task between the folder deletion and the start of the compilation?

Upvotes: 1

Views: 214

Answers (2)

Vaggelis Larios
Vaggelis Larios

Reputation: 11

After allot of trying , i found the solution . In the build.gradle i had to add the preBuild.finalizedBy(generateCode)

Upvotes: 0

ChristianB
ChristianB

Reputation: 2690

I am not a Gradle expert, so their might be better answers!

In your build.gradle you can create custom tasks and make them depend on other tasks:

// this is your new task
task generateCode() {
  description 'Generates some code...'
  doLast {
    println("generateCode")
    // do your code generation here
  }
}

// put the name of the task you wanna depend on, like: compileSources
project.task("compileSources").dependsOn generateCode

When you call this task ./gradlew compileSources you should see that the custom task generateCode gets executed first.

Upvotes: 0

Related Questions