How to change Gradle installation tasks

I want to edit a gradle task named installDebug. Where is the task (or script) located? Maybe this script is in binary and I am not modifying this?

In fact, I want to start changing something for adb . Example. My task should contain:

  • Run adb as "adb connect 192.168.1.2DUC555"
  • Run the "debugInstall" gradient task, directly.
  • Do something like adb, then open apk on my adb server.

What should I do: Change debugTask if possible? Or edit the build.grade file and create your own script task?

+5
source share
2 answers

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

installDebug is set as far as I remember the Android plugin. Each task consists of actions that are performed sequentially. Here is a place to start.

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

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 are added to the installDebug task. If you run gradle installDebug , the first action will be performed, then the task itself, and finally the second action that will be defined. This is all in general.

+3
source

You can add the task to your build.gradle and call it on the command line. This is what I did:

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

then i call gradle adbConnect connectedCheck but you can use gradle adbConnect debugInstall

+2
source

Source: https://habr.com/ru/post/1207764/


All Articles