Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio - gradle task to execute after SYNC

Is there a way to execute gradle task once after project Sync with Gradle files is complete?

I've tried to set task dependency to preBuild, as I've seen gradle:build is triggered when Sync is executing. But the problem is that dependency doesn't seem to work, task is not executed and I have to manually start the task after each Sync.

This is basically what I've tried so far

apply plugin: 'com.android.library'
...

task myTask {
    ...
}
gradle.projectsEvaluated {
    preBuild.dependsOn(myTask)
}

I've also tried to set task dependency to other tasks that I see are triggered (:generate{Something}), but that wasn't successful either.

Is there anything I can to do force the gradle task to be executed after each Sync? I'm using Gradle 2.2.1 + Android Studio 1.0.2

like image 274
doodeec Avatar asked Jan 07 '15 09:01

doodeec


1 Answers

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"
}
like image 138
Alex Cohn Avatar answered Oct 24 '22 06:10

Alex Cohn