Android Studio:如何在运行或调试之前自动卸载APK(或执行adb命令)? [英] Android Studio : How to uninstall APK (or execute adb command) automatically before Run or Debug?

查看:395
本文介绍了Android Studio:如何在运行或调试之前自动卸载APK(或执行adb命令)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我需要在Android Studio中的Run\Debug之前每次都卸载该应用程序.因为我需要在运行\ debug应用程序之前重新创建数据库.我知道我可以运行命令

Now I need to uninstall the App every time before Run\Debug it in Android Studio. Because I need to re-create the database before I run \debug the app. I know I can run the command

adb uninstall [package_name]

在终端中按

清除/data/data/[package_name]下的文件.但这不是我每次必须执行命令的便捷方法.我希望

in terminal to clear the files under /data/data/[package_name]. But it's not convenient way if I have to execute the command every time. I hope the

adb uninstall

单击Run\Debug按钮时,

命令可以自动执行.

command can be executed automatically when I click Run\Debug button.

推荐答案

adb uninstall <package_name>

可用于通过PC卸载应用程序.如果您希望每次通过Android Studio启动应用程序时自动发生这种情况,可以执行以下操作:

can be used to uninstall an app via your PC. If you want this to happen automatically every time you launch your app via Android Studio, you can do this:

  1. 在Android Studio中,单击运行"按钮左侧的下拉列表,然后选择编辑配置...".
  2. 在Android应用程序下单击应用程序,然后在常规"标签中,找到标题启动前"
  3. 单击+按钮,选择运行外部工具",然后在弹出窗口中单击+按钮.
  4. 提供一些名称(例如,adb卸载)和描述,并在Program:中键入adb,在Parameters:中键入uninstall <your-package-name>. 在弹出窗口中单击确定"时,请确保选择了新项目.
  1. In Android Studio, click the drop down list to the left of Run button, and select Edit configurations...
  2. Click on app under Android Application, and in General Tab, find the heading 'Before Launch'
  3. Click the + button, select Run external tool, click the + button in the popup window.
  4. Give some name (Eg adb uninstall) and description, and type adb in Program: and uninstall <your-package-name> in Parameters:. Make sure that the new item is selected when you click Ok in the popup window.

注意:如果您的PATH环境变量中没有adb,请在程序:"字段(例如/home/user/android/sdk/platform-tools/adb)中提供adb的完整路径.

Note: If you do not have adb in your PATH environment variable, give the full path to adb in Program: field (eg /home/user/android/sdk/platform-tools/adb).

这篇关于Android Studio:如何在运行或调试之前自动卸载APK(或执行adb命令)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆