Jagger Jagger - 2 years ago 103
Android Question

How to uninstall APK (or execute adb command) automatically before Run or 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]" 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" command can be executed automatically when I click "Run" \ "Debug" button.

Answer Source
  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.

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download