ilw
ilw

Reputation: 2560

How to change Gradle install tasks

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?

Upvotes: 6

Views: 4128

Answers (2)

Opal
Opal

Reputation: 84756

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.

Upvotes: 4

Gerald
Gerald

Reputation: 677

You can add a task to your build.gradle, and call it in command line. This is what I have done :

task adbConnect(type: Exec) {
commandLine 'adb', 'connect', '192.168.200.92'
}

then I call gradle adbConnect connectedCheck, but you can use gradle adbConnect debugInstall

Upvotes: 2

Related Questions