Android Studio - gradle task to execute after SYNC
Some while ago JetBrains extended their idea gradle plugin and now you can write something like
idea.project.settings {
taskTriggers {
afterSync tasks.getByName("myTask")
}
}
You must apply the plugin, such as
plugins {
id "org.jetbrains.gradle.plugin.idea-ext" version "0.7"
}
Inside the Gradle menu (usually located on the upper right corner of Android Studio), there is a list of tasks. By right clicking on the task, it is possible to set Execute After Sync
.
Finally, I've managed to trigger the task on every Sync event.
Apparently gradle.projectsEvaluated
is either not executed at all when syncing, or it is executed after build
task, so the solution is to get rid of it completely
apply plugin: 'com.android.library'
...
task myTask {
...
}
preBuild.dependsOn(myTask)