Android Studio:如何在运行或调试之前自动卸载 APK(或执行 adb 命令)? [英] Android Studio : How to uninstall APK (or execute adb command) automatically before Run or Debug?
问题描述
现在我需要每次在 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:
- 在 Android Studio 中,单击运行"按钮左侧的下拉列表,然后选择编辑配置..."
- 点击 Android 应用程序下的应用程序,然后在常规选项卡中找到启动前"标题
- 点击 + 按钮,选择运行外部工具,点击弹出窗口中的 + 按钮.
- 给出一些名称(例如 adb uninstall)和描述,然后在 Program: 中输入
adb
并在 Parameters: 中输入uninstall
.确保在弹出窗口中单击确定"时选择了新项目.
- In Android Studio, click the drop down list to the left of Run button, and select Edit configurations...
- Click on app under Android Application, and in General Tab, find the heading 'Before Launch'
- Click the + button, select Run external tool, click the + button in the popup window.
- Give some name (Eg adb uninstall) and description, and type
adb
in Program: anduninstall <your-package-name>
in Parameters:. Make sure that the new item is selected when you click Ok in the popup window.
注意:如果您的 PATH 环境变量中没有 adb,请在 Program: 字段中提供 adb 的完整路径(例如/home/user/android/sdk/platform-tools/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屋!