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:
- 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.
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"
Related Topics
Timepicker in Preferencescreen
Android Hide/Unhide App Icon Programmatically
Programmatically Update Widget from Activity/Service/Receiver
Android Image View Pinch Zooming
How to Detect the Swipe Left or Right in Android
Full Webpage and Disabled Zoom Viewport Meta Tag for All Mobile Browsers
Android Lollipop, Appcompat Actionbar Custom View Doesn't Take Up Whole Screen Width
How to Create a Simple Divider in the New Navigationview
Android Animation Is Not Finished in Onanimationend
How to Display Custom View in Actionbar
Multiline Edittext with Done Softinput Action Label on 2.3
How to Enable Logging for Apache Commons Httpclient on Android
Usb Device Access Pop-Up Suppression
Using Viewpagerindicator Library with Android Studio and Gradle
Show Timepicker with Minutes Intervals in Android