Problem:
You want to add a custom task to the overall build process.
Solution:
Use the Dependon property to insert your task into the directed acyclic graph
Discuss:
During the initialization phase, Gradle sets the task to a sequence based on the dependencies. The result is a DAG. For example, the Gradle record generates a DAG for the Java plugin, such as:
"directed" means that each dependent arrow has only one direction. "Acyclic" means there is no loop in the chart.
Adding a custom task to the main process means inserting your task in the appropriate place on the chart.
Section 4.1 of the COPYAPKS task is defined to copy the generated apk into a separate directory. For simplicity this task is reused:
If the APK is not generated, this task is of no practical use. Assemble task Generation apk. If you use it as a dependency on the COPYAPKS task:
The dependency on Assembledebug means that the debug apk will be generated before the copy task executes. You can use assemble instead, so you are using the release apk.
If you want to run the COPYAPKS task at build time, you can rely on it as a build task. Such as:
Running the build task now also copies the APKs to a separate folder. You have used the correct information to insert the COPYAPKS task into the DAG.
Removing all the apk from the generated APKs directory can also be the same way. The root directory has a clean task that we can edit:
The delete task accepts a list of files or folders to do more, and it is easy to modify the task, such as:
Any custom task can be added to the build process through such a mechanism.
Android Development: "Gradle Recipes for Android" read notes (translation) 4.2--Add a custom task