204

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.

girish946
  • 745
  • 9
  • 24
Jagger
  • 2,352
  • 2
  • 13
  • 12
  • It re-installed your app at the beginning of "Run"/"Debug" process, doesn't it? Or do you mean to uninstall another app? – cck3rry Sep 19 '14 at 05:57
  • @cck3rry Sorry, maybe it's not very clear. I want to execute the command "adb uninstall" because I need to re-create the database before I run / debug the app. – Jagger Sep 19 '14 at 06:02
  • Why don't you take a different approach and write a few lines of code that will delete the database in onCreate of your first Activity? You can then recreate it after that. Just remember to delete this block before you release. – mattgmg1990 Sep 19 '14 at 06:10
  • @mattgmg1990 That means I need to add/ remove such code every time when I do git pull/ push. What a pain... – Jagger Sep 19 '14 at 06:20
  • @Jagger You could use git stash or make a branch. I'm glad you found a better solution that does exactly what you want though in the accepted answer. – mattgmg1990 Sep 19 '14 at 15:14
  • 1
    [This](http://stackoverflow.com/a/28077408/4128308) answer could be useful for you – PavelGP Apr 25 '16 at 08:24
  • @mattgmg1990 Hacking code is a fun, but not good for a product. – Jagger Dec 12 '16 at 01:25

12 Answers12

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

aravindsagar
  • 3,852
  • 1
  • 16
  • 18
  • 2
    a few tips / notes: if you are running more than one emulator or device, then you will want to include adb -s . Macros in Android Studio do not work properly (v1.50.x), so you have to put in the full path for adb or in environment path. – Nick Feb 05 '16 at 19:29
  • @aravindsagar I listed all packages of my device and my app's package name was not there but still it's showing **Failure [DELETE_FAILED_INTERNAL_ERROR]** any idea why is this happening?? – Dinesh Falwadiya May 28 '18 at 12:46
  • that doesn't get rid of preinstalled applications right? – abhimanyuaryan Aug 12 '20 at 08:17
106

example

adb uninstall com.my.firstapp
Jahid
  • 21,542
  • 10
  • 90
  • 108
Thiago
  • 12,778
  • 14
  • 93
  • 110
  • 6
    If don't know pakage name, but have the apk, can get it with this http://stackoverflow.com/a/37324607/812915 – equiman May 19 '16 at 14:39
36

This command with --user 0 do the job:

adb uninstall --user 0 <package_name>
29

List the packages by:

adb shell su 0 pm list packages

Review which package you want to uninstall and copy the package name from there. For example:

com.android.calculator2

Lastly type in:

adb uninstall com.android.calculator2 

and you are done.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
kamran khader
  • 329
  • 3
  • 3
  • 9
    For the non-rooted folks, omit `su 0` from the list packages command. – villecoder Mar 08 '18 at 16:01
  • 2
    If you have a lot of apps installed, adding `| grep -i ` at the end of the above command can help narrow down the list. For example, to find the Google Maps package, you can use `adb shell pm list packages | grep -i map`. – hBrent Sep 08 '20 at 20:19
25

If you want to uninstall when connected to single device/emulator then use below command

adb uninstall <package name>

else with multiple devices then use below command

adb -s <device ID> uninstall <package name>
summerGhost
  • 477
  • 4
  • 15
12

I am using Android Studio 2.1.2. I had same requirement as OP. Though above two answer seemed to help everyone, it did not work for me . I am sharing what worked for me.

Go to main menu/Run/Edit Configuration . Select app under Android Application on the left.This should open multi-tabbed pane . Select General tab ( would be default), click green + sing at the bottom ( below text Before launch: Gradle -awake ...).

A drop down will appear, select Gradle-aware-make option. Another text box will pop up. enter :app:uninstallAll in this text box . (You can use ctrl + space to use autocomplete todetermine right target without typing everything . And also helps you choose the right app name that is avaiable for you). and set apply/ok. Relaunch your app.

Note : Every time you launch your app now , this new target will try to uninstall your app from your emulator or device. So if your testing device is not available, your launc will probably fail while uninstalling but will continue to start your emulator. So Either start your emulator first, or re-lauch after first fail again ( as first launch will start emulator though uninstall fails).

Jimmy
  • 2,589
  • 21
  • 31
  • 1
    This works nicely, but you need to replace `app` with the name of your actual module, such as `myMainApp`. – Jimbali Jul 13 '16 at 18:44
  • 1
    yup, just use `ctrl` + `space` on the popup to use autocomplete. It determines the app as well. – Jimmy Oct 11 '16 at 15:37
11

Use this cmd to display the packages in your device (for windows users)

adb shell pm list packages

then you can delete completely the package with the following cmd

adb uninstall com.example.myapp

Ang67
  • 126
  • 1
  • 3
8

To add to above, if you can list and grep via:

$ adb shell pm list packages | grep -i <some_idea>

it will give you the name of the app, if you have some idea what the name of the package could be.

For example,

$ adb shell pm list packages | grep -i cal

package:com.android.providers.calendar

package:com.google.android.calendar

Then you can proceed with:

$ adb uninstall <package_name>
denhamnyc
  • 81
  • 1
  • 3
7

I use an Android Studio plug-in called "adb idea" -- has a drop down menu for various functions (Uninstall, Kill, Start, etc) that you can target at any connected or simulated device. One could argue it takes me a step away from having a deeper understanding of the power of adb commands and I'd probably agree....though I'm really operating at a lower level of understanding anyway so for me it helps to have a helper. ADB Idea enter image description here

Gk Mohammad Emon
  • 6,084
  • 3
  • 42
  • 42
Joel Butler
  • 240
  • 3
  • 15
3

A simple three-step process (checked on mac terminal)

  1. Connect your android device (please connect 1 android Device at a time), preferably by a cable & Confirm connection by (this will list Device's ID device ID)

    adb devices
    
  2. Then to list all app packages on the connected device by running, on terminal

    adb shell pm list packages -f -3 
    
  3. Then uninstall as explained earlier

    adb uninstall <package_name> 
    
eaccmk
  • 366
  • 2
  • 6
2

Above answers are correct, however please make sure about the package names as they are case sensitive, since its a shell where the command is going to run.

adb shell pm uninstall com.company.PacKaGeIsCaseSenseTiVe

or directly

adb uninstall com.company.PacKaGeIsCaseSenseTiVe

Ranvir
  • 2,094
  • 2
  • 19
  • 26
0

Run script before launch

Edit Configurations... -> Select App -> Before Launch + -> Run External tool + -> Name, Program adb, Arguments uninstall <package_name>
yoAlex5
  • 29,217
  • 8
  • 193
  • 205