Android 在执行测试之前,如何要求gradlew卸载应用程序?

Android 在执行测试之前,如何要求gradlew卸载应用程序?,android,gradle,android-gradle-plugin,android-espresso,gradlew,Android,Gradle,Android Gradle Plugin,Android Espresso,Gradlew,我使用,来配置我的Android Studio,在它执行浓缩咖啡测试之前,卸载上一个应用程序 因此,在Run->Edit Configurations->Before launch中,然后添加了:app:uninstallAll,因此,当我从AS运行我的测试用例时,我只选择了配置,它工作得很好 我使用/gradlew connectedAndroidTest从命令行执行Espresso测试。但是,我想知道 在执行测试之前,我如何要求gradle的命令行卸载以前的版本?您可以使用adb卸载以前的

我使用,来配置我的Android Studio,在它执行
浓缩咖啡
测试之前,卸载上一个应用程序

因此,在
Run->Edit Configurations->Before launch
中,然后添加了
:app:uninstallAll
,因此,当我从AS运行我的测试用例时,我只选择了配置,它工作得很好

我使用
/gradlew connectedAndroidTest
从命令行执行Espresso测试。但是,我想知道


在执行测试之前,我如何要求gradle的命令行卸载以前的版本?

您可以使用adb卸载以前的版本示例:

unistall old apk 卸载测试 设备连接设备 packageName—应用程序的程序包名称


希望这有帮助:)

您可以使用adb卸载以前的版本示例:

unistall old apk 卸载测试 设备连接设备 packageName—应用程序的程序包名称


希望这有帮助:)

您不能询问Gradle的命令行-但Gradle可以询问命令行提示

根据此答案,可以轻松创建所需的应用程序卸载
Exec
任务:

task uninstallApp(type: Exec) {
    def uninstallCommand = ['adb', 'shell', 'pm', 'uninstall', 'com.acme.coyote']
    commandLine uninstallCommand
}
可以使用
task.finalizedBy
task.dependsOn
添加此任务

也请看我的这篇文章,它解释了如何处理共享偏好


因为当从备份中恢复这些首选项时;它不是新安装。

您不能询问Gradle的命令行-但Gradle可以询问命令行提示符

根据此答案,可以轻松创建所需的应用程序卸载
Exec
任务:

task uninstallApp(type: Exec) {
    def uninstallCommand = ['adb', 'shell', 'pm', 'uninstall', 'com.acme.coyote']
    commandLine uninstallCommand
}
可以使用
task.finalizedBy
task.dependsOn
添加此任务

也请看我的这篇文章,它解释了如何处理共享偏好

因为当从备份中恢复这些首选项时;这不是新安装的

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