37

I can uninstall an app on the device from my computer using adb uninstall <package_name>, but I'd like to do the same with a script on the actual device.

I've also tried running an android.intent.action.DELETE intent using am but it prompts the user for confirmation.

Given that the device is rooted, is it possible to run a command on the device to uninstall an app without requiring user action/confirmation ?

George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • I think this is only on topic on [android.se] now. Questions about basic installation and uninstallation have been deemed off-topic on StackExchange – Evan Carroll May 26 '18 at 21:00
  • Did you ever figure out how to run some script on the device? How do you get a command line? or do we have necessarily to install some app like "cancer" Termux? a sample script would be nice? I think it has to start with #! /system/bin/sh – Meryan May 18 '22 at 05:49
  • I needed to uninstall the app silently (without) the action/confirmation dialog, so, on a rooted device, prefixing the `pm uninstall` command with `su -c` [did the trick](https://stackoverflow.com/questions/17556750/how-to-uninstall-an-android-app-from-command-line-on-the-device?noredirect=1#comment25540140_17556878). I needed to trigger it from inside my Android app, so used something very similar to [noman's approach](https://stackoverflow.com/questions/17556750/how-to-uninstall-an-android-app-from-command-line-on-the-device?noredirect=1#comment40067501_17556878) – George Profenza May 18 '22 at 12:54

9 Answers9

60

Trying using the pm command:

pm uninstall <package_name>

or

pm uninstall -k <package_name>

The -k flag keeps the data and cache directories after the package is removed.

I haven't tested this myself, but I don't think this should show a warning message.

Frxstrem
  • 38,761
  • 9
  • 79
  • 119
  • 1
    Thanks!(+1) That worked. Depending on the situation `su -c pm uninstall [-k] ` does the trick if the simply calling pm fails. – George Profenza Jul 09 '13 at 19:56
  • 2
    @RaghavSood You should not do `rm ` thing as it would leave a lot of garbage to system and that crap will still use storage space (for example, cached apk), and is hard to find without knowledge of system (stuff scattered around filesystem). If you know what you are doing, then why not but plain `rm apkfile` won't do any good. – Sampo Sarrala - codidact.org Feb 21 '14 at 20:55
  • Thank you for the answer. .This one worked for me: String cmd = "su -c pm uninstall " + packageName;Runtime.getRuntime().exec(cmd); ... !!! – Noman Sep 03 '14 at 11:49
  • @Frxstrem How to update the app please give the adb comments sir – Gowthaman M Jul 17 '18 at 10:45
14

To forcefully uninstall the system user apps:

Use:

adb shell pm uninstall --user 0 <package_name>
Raj Yadav
  • 9,677
  • 6
  • 35
  • 30
  • Yes, most of the devices install application for primary user and uninstall command without specifying user fails. That's the reason I mentioned the word forcefully in there. – Raj Yadav Feb 21 '20 at 10:48
13

adb shell pm uninstall *your.package.name*

Did the trick for me.

Distwo
  • 11,569
  • 8
  • 42
  • 65
  • In my case I get a `java.lang.IllegalArgumentException` when using `*` to delineate package name. Worked with double quotes – Nicu Surdu Aug 30 '17 at 10:03
12

And if you want to re-install back package removed for a user (i.e. pm uninstall --user 0), without root:

pm install --user 0 $(pm dump <package name> | awk '/path/{ print $2 }')

This will locate .apk of the uninstalled package: pm dump <package name> and search for a line starting with path: to obtain path to the .apk (note that pm path <package> won't work for an uninstalled app) and install it using pm install --user 0 (note that pm install without --user argument wont' work).

This works for any system app, this is a good alternative to pm disable-user <package> which still allows you to easily enable app back via Settings. For example, you could uninstall Play Store (pm uninstall --user 0 com.android.vending) and have no way to enable/install any application on default non-rooted device without access to adb or pm.

Artur Rashitov
  • 474
  • 4
  • 12
  • 1
    This is a very useful and severely underrated answer. – Selivanov Pavel Feb 05 '20 at 00:18
  • How do you get a command line on android 11 device? or do we have necessarily to install some app like Termux? a sample script would be nice? I think it has to start with #! /system/bin/sh then your pm install ... commands... Thank you. – Meryan May 18 '22 at 05:51
3

Some Apps can't be uninstalled,so below command gives the error:

adb shell pm uninstall package_name
Failure [DELETE_FAILED_INTERNAL_ERROR]  

Try to run disable command instead,

adb shell pm disable package_name
Package package_name new state: disabled 
rahul2907
  • 31
  • 3
2

I had fail on uninstall some system launchers (for example NovaLauncher) In this case I recommend to use "disable" instead "uninstall":

pm disable <package_name>

In result you hide this system launcher (sys app) from list of launchers when you have a few launchers

Webest
  • 51
  • 4
1

Simple command to remove any app from the device, try this:

 pm uninstall --user 0  

This command will forcefully remove that app from the device.

abhi618
  • 21
  • 1
1

If you have an rooted android device then you can easily uninstall pre-installed apps from your device. My OnePlus device is rooted with Magisk manager.

Rooting an Android device gives you admin privileges towards your device and so you can easily install or uninstall any system application.

However, command line method also works most of the time. I have tested adb method on MIUI device for removing bloatware.

You can follow stackoverflow read this thread....

ADB command: pm uninstall -k <package_name>

shivlal kumavat
  • 868
  • 1
  • 12
  • 28
Rekha
  • 11
  • 1
0

Trying using the adb command:

adb uninstall <package-name>

make sure your device is connected

Surender Kumar
  • 1,152
  • 16
  • 17