3

Before running my application I would like to uninstall any instances on the device. Running the task uninstallAll manually does this perfectly.

How can I call this command from my build.gradle so that this occurs each time automatically?

Opal
  • 81,889
  • 28
  • 189
  • 210
Ryan R
  • 8,342
  • 15
  • 84
  • 111

1 Answers1

2

What you may need is to set defaultTasks:

defaultTasks uninstallAll

or specify appropriate tasks dependencies:

runTaskName.dependsOn(uninstallAll)
Opal
  • 81,889
  • 28
  • 189
  • 210
  • Where should I place these in my `build.gradle`? Within any section? – Ryan R May 06 '15 at 20:02
  • Out of any section, *just in* `build.gradle` itself. – Opal May 06 '15 at 20:03
  • 1
    I'm getting the following errors respectively for each method: `Error:(1, 0) Could not find property 'uninstallAll' on project ':App'.` and `Error:(52, 0) Could not find property 'runTaskName' on project ':App'.` – Ryan R May 06 '15 at 20:06
  • Do you have task `uninstallAll` defined? Do you run it with gradle? When it comes to `runTaskName` it's not exact.. You should replace it with task name used to run the application.. – Opal May 06 '15 at 20:10
  • Yes when I open the Gradle pane in AS, the task is listed un `:App > Tasks > install > uninstallAll`. When I run it from here manually it works fine. – Ryan R May 06 '15 at 20:20
  • 1
    Ah it needs to be `defaultTasks 'uninstallAll'` but this did not work. – Ryan R May 06 '15 at 20:23
  • Ok, so how you run the application? – Opal May 06 '15 at 20:31
  • `Shift+F10` as usuall. One solution is to edit the configuration and add `uninstallAll` to the Before Launch section, though this will not be tracked in git. – Ryan R May 06 '15 at 20:37
  • Is there any task invoked after running with Shift + F10? – Opal May 06 '15 at 20:38
  • It launches `assembleDebug` as usual. – Ryan R May 06 '15 at 20:40
  • Basically I meant `runTaskName` to be `assembleDebug`. – Opal May 07 '15 at 07:44
  • Cool thanks. I was getting confused because AS was showing it as an undefined symbol. – Ryan R May 07 '15 at 15:05