23

I am new to Android Studio and I feel that I must be doing something wrong. When running MyApp on an actual device the process goes like this.

  • Edit code.
  • Select the Run command in Android Studio. (Shift+F10)
  • Discover a Bug (on phone)
  • Navigate to Settings --> Application --> MyApp (on phone)
  • Force Stop (on phone)
  • Uninstall MyApp (on phone)
  • Edit code
  • Select the 'Run' command in Android Studio.
  • Repeat again and again.

This is repetitive and time consuming. Is there a way to uninstall MyApp via Android Studio?

If not is there some other more automated way to do this?

BTW I have seen this question How to automatically uninstall android app from device before installing a new version but it does not sufficiently address the issue.

Community
  • 1
  • 1
nu everest
  • 9,589
  • 12
  • 71
  • 90
  • 1
    1. fix the bug 2. Shift+F10 is enough(it should update the app) ... why you are uninstalling the app ? – Selvin Feb 23 '15 at 17:15
  • 2
    If you need to specifically test what the app is doing on first install, here's a hack you can do: set the version code to a high number, and then decrease it by one each time you run the app. Android Studio will detect that the device already has a newer version and offer to uninstall it. – nasch Feb 23 '15 at 17:28
  • Possible duplicate of [How to automatically uninstall android app from device before installing a new version](http://stackoverflow.com/questions/28076751/how-to-automatically-uninstall-android-app-from-device-before-installing-a-new-v) – UmAnusorn Jan 24 '17 at 10:39
  • @umitems That question does not result in the answer I was looking for nor is that question as specific as this one. – nu everest Jan 24 '17 at 14:22

5 Answers5

92

I think this answer is what you're looking for. Basically edit your configuration to perform an uninstall before app launch.

From the Run menu -> Edit Configurations... -> Before Launch -> Add Gradle-aware Make -> ":app:uninstallAll"

enter image description here

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
Frank Yin
  • 1,920
  • 1
  • 17
  • 12
  • 6
    This answer helped me more than the accepted one. Later versions of AS have an issue with not being able to detect whether you've uninstalled an APK and will try to install "restart patches" instead, but they fail if the APK was uninstalled due to clearing databases, clean installs, etc. – Andrew Quebe May 06 '16 at 04:27
  • This is the best answer! Thanks. – Dody Rachmat Wicaksono Jun 29 '16 at 00:49
  • This is what I'm looking for – UmAnusorn Jan 24 '17 at 10:38
  • You really helped me. My cellphone got a dark screen because of my app, so I needed to uninstall the app, but with my cellphone in dark the only solution was uninstall that app from Android Studio. I did not think it was even possible, but it worked. Thank you ! My cellphone is OK now. However, I need to know why this happen. Thanks ! – Gunnar Sep 18 '19 at 22:32
  • This is not the right answer to the question. BUT, due to the tittle of the question (that is wrong too), all people that are ending on this page are looking for this information (instead of the right answer). – mgueydan Jun 28 '20 at 22:53
10

You can execute the gradle task :app:uninstallAll to uninstall the app. The next time you hit Run your app will be reinstalled.

Android Studio Gradle Tab with selected uninstallAll task

TheDarkTron
  • 304
  • 4
  • 13
4

You can skip the force stop and uninstall step by just hitting run again. Android Studio should prompt you which device to run on and there you can select your connected device.

It will close the app and re-run your changed version.

Kasper Agg
  • 107
  • 1
  • 7
4

You can make just like this now. Check mark on Clear app storage before deployment.

enter image description here

enter image description here

UPD: Unfortunately it need to make for all new projects each time. But solution works super good.

Dyno Cris
  • 1,823
  • 1
  • 11
  • 20
2

I always just hit the "debug" icon (the bug icon) and from the debug tab (at the bottom of your screen), you can stop running the app by clicking on the stop button. No need to uninstall/reinstall app. When you're done, you can do a release build of the apk.

Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106