1

I've created a custom task in the project's build.gradle file like so:

task buildAllForAppRelease {
    dependsOn(':clean', 'app:assembleDebug', ':clean', 'app:assembleRelease', 'app:bundleRelease')
}

The apks and bundles are all built, but the clean task doesn't seem to do anything. It shows up in the build output but no files are getting deleted.

When I run the clean task directly, it does what it is supposed to do.

How can I ensure, that clean task is actually run before the other tasks?

Btw. I've set org.gradle.paralell=true, but that shouldn't have an influence, does it?

Ridcully
  • 23,362
  • 7
  • 71
  • 86
  • According to this [answer](https://stackoverflow.com/a/21613379/11301941) , there is no guarantee that the tasks will be ran in order using `dependsOn`. I've encountered a similar issue before, even `mustRunAfter` did not help organize the order. My naif solution was [this](https://stackoverflow.com/a/74260824/11301941), messy code but strictly ordered tasks. I dont know if such a solution would be sufficient in you case. as you will need to create 3 extra tasks for each build, and a forth task `buildAllForAppRelease ` which will call all of them in the desired order after a valid clean. – George Jan 11 '23 at 11:52
  • 1
    @George For now, I removed clean from the dependsOn and create a Gradle 'Run Configuration' in AndroidStudio. There I put clean and buildAllForAppRelease in the tasks field and that does the trick. – Ridcully Jan 11 '23 at 14:34

0 Answers0