1

I use this solution, to configure my Android Studio, to uninstall the previous app, before it executes the Espresso tests.

So, in Run -> Edit Configurations -> Before launch and then added the :app:uninstallAll so, when I run my testcase from AS, i only select the configuration, and it works well.

enter image description here

I use the ./gradlew connectedAndroidTest to execute the Espresso test from command line. But, I am wondering,

How may i ask the commandline of gradle to uninstall the previous version, before execution of test?

Sal-laS
  • 11,016
  • 25
  • 99
  • 169

2 Answers2

1

You can use adb to uninstall previous version example:

unistall old apk

adb -s $device uninstall ${packageName}.debug

uninstall test

adb -s $device uninstall "com.bookings.test"

device - connected device packageName - package name of the app.

Hope this helps :)

ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
Zia
  • 2,365
  • 2
  • 17
  • 14
0

you cannot ask the command-line of Gradle - but Gradle can ask the command-line prompt.

based upon this answer here, one can easily create the desired application uninstall Exec task:

task uninstallApp(type: Exec) {
    def uninstallCommand = ['adb', 'shell', 'pm', 'uninstall', 'com.acme.coyote']
    commandLine uninstallCommand
}

this task can be added, either with task.finalizedBy or with task.dependsOn.

also see this answer of mine, which explains how to deal with shared preferences ...

because when these preferences are being restored from backup; it's no fresh install.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216