Execute multiple tasks before assembleRelease
Execute multiple tasks before assembleRelease
I have two tasks, a test
-task and a poeditorPull
-task (which pulls the latest strings from the poeditor-api) and I want my assembleRelease-task to run after both have finished.
test
poeditorPull
So far, I've used task.dependsOn
, but yesterday I found out that gradle finishes building the apk before the poeditorPull-task finishes
task.dependsOn
tasks.whenTaskAdded
As I said earlier, this doesn't do what I want, namely enqueue the tasks test
and poeditorPull
before assemble*Release
test
poeditorPull
assemble*Release
how do I go about this?
2 Answers
2
I have re-phrased my answer to make it more concise and clear...
Problem is that assemble*
tasks are created dynamically by Android plugin, so in your build script you cannot reference directly these tasks. You should use afterEvaluate
block :it will be executed after all tasks have been created, so you will be able to create dependency from 'assembleInternalRelease' to your own tasks
assemble*
afterEvaluate
afterEvaluate project ->
assembleInternalRelease.dependsOn tasks.getByName('test')
// or tasks.getByName('assembleInternalRelease').dependsOn tasks.getByName('test')
what is the error message you get? else you can try to use "tasks.getByName(String taskName)" instead, it should work (edited my answser with the other syntax)
– M.Ricciuti
Sep 18 '18 at 8:28
apparently, the android-plugin doesn't know the tasks
assembleReleaseInternal
and assembleReleaseProduction
. gradlew tasks
only displays assembleRelease
. I've tried all three variants, the Android Gradle Plugin in Android Studio doesn't recognize either of them. I'm guessing that's a bug with the android plugin itself– TormundThunderfist
Sep 18 '18 at 10:35
assembleReleaseInternal
assembleReleaseProduction
gradlew tasks
assembleRelease
one suggestion, in order to confirm my assumption: can you try to move your initial code block
tasks.whenTaskAdded ...
before the line apply plugin: 'com.android.application'
? It should normally create the dependencies properly.. to be confirmed.– M.Ricciuti
Sep 18 '18 at 12:25
tasks.whenTaskAdded ...
apply plugin: 'com.android.application'
it behaves the same way it does when the block is below the plugin-stuff. I assume that the
assemble
-task is too late in the chain (in fact, it's the last task that's executed). I guess I have to hook into a different task– TormundThunderfist
Sep 18 '18 at 12:50
assemble
as it turns out, the code was working fine, but since the plugin works asynchronously, it's impossible to have my task wait on completion
@M.Ricciuti sorry for wasting your time, thanks nonetheless
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy
I've tried adding the following code gist.github.com/TormundsMember/2f74cd708e02e460fde909cc57ea4c37, gradle didn't recognize the tasks, the internet told me to put them in quotation-marks, which means that now i'm working with strings inside the lambda. thanks for trying to help though, much appreciated
– TormundThunderfist
Sep 18 '18 at 8:22