Android Studio:How to Uninstall APK (Or Execute Adb Command) Automatically Before Run or Debug

Android Studio : How to uninstall APK (or execute adb command) automatically before Run or Debug?

adb uninstall <package_name>

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

How can I remove an .apk from a device with adb

adb uninstall com.company.apppackage

How to automatically uninstall android app from device before installing a new version

Apparently, if you in Run -> Edit Configurations..., on the left side there is a expendable list of Android configurations.

Select yours, on the right side of the window are details on the configuration, at the bottom of that section is the Before launch section.

Create a gradle-aware Make, given the task :app:uninstallAll or :app:uninstallDebug whichever suits you. (There is autocompletion to get all the available tasks, app may vary if you have several modules).

Uninstalling APK : one last action before uninstall

You are correct. There is no such event, and there is no supported way to get notified when your application is being uninstalled. Application's process is simply killed (if it was running) and application is uninstalled.

Adb daemon doesn't start automatically

Thanks to this answer. Resolved by disabling adb mDNS for wireless debugging:

Android Studio > Settings > Build, Execution, Deployment > Debugger > Untick "Enable adb mDNS for wireless debugging"

Sample Image



Related Topics



Leave a reply



Submit