Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using Android studio with Gradle builds. I test my app on a device and let Android Studio and Gradle build the app and install it on the device. How can I tell Gradle or Android Studio to uninstall the app from the device before installing a new version?

like image 296
Deepak Azad Avatar asked Jan 21 '15 21:01

Deepak Azad


People also ask

Can an Android app Uninstall itself?

No you simply can't. At least not for the phones that are not rooted. You can take the user to an Uninstall screen, but they would have to click on "Uninstall" to uninstall the app. For more information visit install/uninstall application programmatically.

What is the 1st step you should do when you Uninstall an app from an Android device?

The first thing you should do is open the Settings menu on your device. After that, open Apps, find the app you want to delete, select it, and tap on the Uninstall button. Hit OK. The app will be deleted from your device in a matter of seconds in most cases.


2 Answers

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

like image 91
njzk2 Avatar answered Sep 18 '22 17:09

njzk2


The current answer is a little outdated, these are the simplest steps:

  • Select Edit Configurations from the dropwdown
  • Find the section Before Launch: Gradle task, Gradle-aware Make
  • Click + and choose Run Gradle task
  • In the Gradle project field, select the root of your project
  • In the Tasks field enter :app:uninstallAll or equivalent
  • Leave the other fields blank and press OK
  • Reorder the tasks so your new one is first / top of the list
like image 25
Nick Cardoso Avatar answered Sep 17 '22 17:09

Nick Cardoso