Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Gradle install tasks

Tags:

android

gradle

I want to edit gradle task named installDebug. Where is the task (or script) located? Maybe this script is located in binary code and I'm not change that?

Really, I want run edit something option for adb. Example: My task must contain:

  1. Run adb like "adb connect 192.168.1.2:5555"
  2. Run "debugInstall" gradles task, directly.
  3. Do something, like - adb then open apk on my adb server..

What I should do: Edit debugTask if possible? Or edit build.grade and make own task script?

like image 404
ilw Avatar asked Nov 26 '14 20:11

ilw


1 Answers

All the tasks are located in build.gradle script itself or in the plugin that is applied at the beginning of the script.

installDebug task is provided by as far as I remember android plugin. Every single task consists of actions that are executed sequentially. Here's the place to start.

You can extend a task adding action to the beginning of at the end of internal actions list.

So:

//this piece of code will run *adb connect* in the background
installDebug.doFirst {
   def processBuilder = new ProcessBuilder(['adb', 'connnect', '192.168.1.2:5555'])
   processBuilder.start()
}

installDebug.doLast {
   //Do something, like - adb then open apk on my adb server..
}

Here, two actions were added to installDebug task. If you run gradle installDebug, first action will be run, then the task itself and finally the second action that is defined. That's all in general.

like image 103
Opal Avatar answered Oct 23 '22 12:10

Opal