How to run a task at any stage of an app Gradle build
![Oscar de la Hera Gomez](https://www.delasign.com/CDN/headshots/profile.webp)
![Two flowers that represent Kotlin and Android Studio. Beneath them sits the text "App Kotlin Gradle DSL Build Task."](https://www.delasign.com/CDN/images/How-to-run-a-task-at-any-stage-of-an-app-Gradle-build.webp)
A step by step guide on running a task during any part of the build stage of an App Gradle Kotlin DSL in Android Studio.
Step One: Select the App Gradle
![A screenshot of Android Studio with the App build.gradle.kts file highlighted. We have also highlighted the android section of the gradle.](https://www.delasign.com/CDN/images/Find-Gradle.webp)
In Android Studio, open the build.gradle.kts, under the app folder.
Find the Android section.
Step Two: Add the build listener
![A screenshot of Android Studio showing the build listener added to the gradle. This code is available below. Make sure you place it within the android section.](https://www.delasign.com/CDN/images/Add-Listener.webp)
Within the android section, add the script below.
Step Three: Add the Task
![A screenshot of Android Studio showing the build listener added to the gradle. This code is available below. Make sure you place it within the android section.](https://www.delasign.com/CDN/images/Add-Listener.webp)
Add wherever tasks you wish to run to the relevant part of the build phase.
Please note that the Gradle only seems to detect projectsEvaluated (pre-build) and buildFinished (post-build).
Step Four: Test
![A screenshot of Android Studio showing the code we added above, along with the sample logs that appear for the projectEvaluated and buildFinished parts of the build listener.](https://www.delasign.com/CDN/images/Run_2023-06-08-192315_pvtm.webp)
Sync your Gradle, and see how the task(s) are ran.
Looking to run a task outside of the App Gradle?
If you are looking to run gradle tasks outside of the App build.gradle.kts, consult the tutorial below:
Any Questions?
We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.