Adding steps to the Android build

Hi guys,
I’m currently writing a Gradle plugin, where I need to add some steps (new tasks) within the Android build flow.
The Android build runs many tasks, but let’s assume for simplicity that it runs the javaCompile task, and then the Dex task.
The Dex task uses the output of the javaCompile task. So we have:

javaCompile > Dex

Now, I would like to add a step in the middle, so that it works like this:

javaCompile > MyTask > Dex

In other words, I would like to have MyTask work on the output of javaCompile, produce a new output, and have the Dex task use the output of MyTask instead of the output of javaCompile.
I was able to change the output folder of the javaCompile task, but then the Dex task took its files from the new folder, which was not what I wanted.
Eventually I was able to change the input dir of the Dex task, so that it takes its files from MyTask instead of javaCompile. However, I did it by looking at the Android plugin source code, and relied on the input field inside the Dex task. This means that if Google decide to change their implementation later on – my plugin will stop working.
I was wondering whether there was a better way, sort of a “standard way” of achieving what I want within Gradle, without relying at all on the internals of the Android implementation?

Thanks!
Ariel

There isn’t a standard Gradle way of doing this since the Android tasks are custom task types. It’s up to the author of those tasks to document the task API, and ensure public APIs don’t change. Unfortunately, when it comes to the Android side of things, anything outside of the android { } DSL isn’t really documented, so like you said, it’s very possible the implementation for the Dex task may change in the future. Personally, I’d say the way you are going about it the best, and realistically, the only way to accomplish what you want.

You might also want to post on the adt-dev list. There might be an alternative way of accomplishing this that I’m not aware of.

1 Like

Thank you Mark.
I will also try to follow your advice and post it also on the adt-dev list.
Ariel