How to uninstall an android app from command line on the device - android

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 ?

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.

To forcefully uninstall the system user apps:
Use:
adb shell pm uninstall --user 0 <package_name>

adb shell pm uninstall *your.package.name*
Did the trick for me.

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.

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

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

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.

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>

Trying using the adb command:
adb uninstall <package-name>
make sure your device is connected

Related

adb Failure [DELETE_FAILED_INTERNAL_ERROR]

I'm dealing with a pretty major malware issue on an Elite 6.0L+ Sky Device. I'm working with a fellow from the malware bytes forums trying to get it cleaned out. I'm trying to uninstall a few apps through adb via command prompt but it's throwing errors.
adb pm shell pm uninstall com.wouzee.hispanopost
That command throws the error:
Failure [DELETE_FAIL_INTERNAL_ERROR]
If I try it as
adb pm shell -k --user 0 uninstall com.wouzee.hispanopost
Then is throws: Failure [no installed for 0]
I have managed to uninstall other things using these commands but the two things I've been told to remove both throw these same errors when I try to remove them.
Does anyone have any idea how to get around this?
I was having the same problem uninstalling with:
adb shell
pm uninstall <package>
This is what worked for me eventually:
adb shell
pm uninstall --user 0 <package>
Some Apps are prevented from uninstalling. You can disable them instead. Use following command on adb shell:
pm disable-user --user 0 <package>
Here is my solution, I uninstall some system apps come up with [DELETE_FAIL_INTERNAL_ERROR] too
use adb shell su to enter shell mode
then using pm uninstall --user 0 <your-pkg-name> to uninstall
PS: if only use adb shell my situation will generate error too, the su is the key to solve problem

Restrict Android Studio from installing in Work Profile [duplicate]

Android 4.2 on tablets added support for multiple users per device (similar to desktop OSes), each of which can install and remove apps independently. Currently, using adb install /path/to/app.apk installs the app globally; every user can see and launch it (as if every user installed the same app from the Play store for example).
Is there a way to adb install an app onto a device so that only one user can see it in the launcher menu?
adb install now supports --user USER_ID argument, so in order to install APK for a certain user, use:
adb install --user USER_ID PATH_TO_APK
In order to find out USER_ID, use adb shell pm list users.
See https://source.android.com/devices/tech/admin/multi-user-testing for details.
pm enable [--user USER_ID] PACKAGE_OR_COMPONENT
pm disable [--user USER_ID] PACKAGE_OR_COMPONENT
pm enable --user 12 org.mozilla.firefox_beta
It may not have a per-user 'adb install', but it does have a per-user 'start' option when you want actual run the APK for testing. By default the documentation says 'start' will just start for the currently running user, but you can do
adb shell am start --user USER activity...
to start the APK as someone else. To get a list of users, run
adb shell pm list users
Here is the full documentation of the adb tool: http://developer.android.com/tools/help/adb.html
adb install doesn't provide any way to specify the target users.
I stumbled across this post when I was having issues installing a React Native app on a phone with a separate Work Profile on it. For some reason, it felt like it was randomly choosing which profile to install the app on.
Here's what I did to specify the user manually:
Build the app at least once:
npx react-native run-android
Uninstall if needed:
adb uninstall <your package name here>
Install the app manually. The APK path should be relative to the top level of your project:
adb install --user 0 ./android/app/build/outputs/apk/debug/app-debug.apk

Best practice for re-installing APK via shell command?

I have a curated Android device that downloads an updated APK from a private server and will re-install the app using a shell command, "pm install -f -r "
The command works, but when the re-install happens, the device shows a popup, saying the app stopped (like it crashed).
Is there a safe way to re-install the app?
Should I be stopping the app first, re-installing then re-starting it?
I don't know is there a problem with this "force close" dialog.
You can try the following:
1) Stop app first, after that re-install it
use:
adb shell am kill [options] <PACKAGE>
or on Honeycomb:
adb shell am force-stop <PACKAGE>
where is the package name for you application.
2) I always do like that:
uninstall application:
adb uninstall <PACKAGE>
and install it again:
adb install <PATH TO APK>
The problem with second solution is that all data cached in Android/data will be removed
Hope it helps.

Android: How to Know if any application is already installed in android device using adb?

I've to install an android app with package name like "com.xyz.game" using adb.
I want to automate the process using shell script. The process will be like if app is already installed, uninstall it(with command adb uninstall com.xyz.game) and install using "adb install game.apk" otherwise simple "adb install game.apk".
How can I achieve this?
[Update 2]
Without using grep
adb shell pm list packages [your.package.name] as mentioned in the below answer
[Update]
According to (also) correct answer below, try grep the result from pm list packages.
adb shell pm list packages | grep com.your.app.package
[Original]
If the application is already installed and if you try to install the same app again, adb will return with an error - Failure [INSTALL_FAILED_ALREADY_EXISTS]. However, if you want to re-install the already installed app, then use -r parameter.
Ex:
adb install -r game.apk
Try grep the result from pm list packages.
adb shell pm list packages | grep com.xyz.game
You may see the result if already installed.
package:com.xyz.game
No need to use grep. Using following commands you can simply check if application is already exist or not.
Run ADB command
adb shell pm list packages [your.package.name]
If app is already installed then above command will return,
package:[your.package.name]
Else it won't return anything i.e. empty String.
Android 7.0 has introduced cmd (a new native code based) tool which allows to interact with Android services like PackageManager much faster than the old java bytecode based tools like pm. So for recent Android versions instead of adb shell pm list packages <package.name.substring> you should use
adb shell cmd package list packages <package.name.substring>
Taking into account #Joel answer, just do it in one-liner
# uninstall only if exists
adb shell pm list packages | grep com.your.app.package && adb uninstall com.your.app.package
Use First adb shell command if you are using adb otherwise you can use use root in same device by su command
Then, we can get path of installed apk files by their pkg names lets say in our case pkg name is com.tencent.ig
pm path com.tencent.ig | sed 's/package://'
If app installed : You will get the path to the apk file
If app not installed : You will get nothing
Previous answers are limited but by using above logic we can also use if statement easily like :
pkg=com.tencent.ig #Add pkg of your app only here
if [ -f $(pm path $pkg | sed 's/package://') ]
then
echo "YES, app is installed"
#further commands if app is installed
else
echo "NO, app is not installed"
#further commands if app not installed
fi
I think that will be much handy.
This works fine :
adb shell pm list packages your.package.name
Replace your.package.name with the required package name.
If app installed : You will get the path to the apk file
If app not installed : You will get nothing

adb uninstall failed

I am writing some sample apps.
After I debug these apps, I don't see an uninstall button in my device's application management.
When I do adb uninstall, it always says Failure without any reason.
In DDMS I saw that my apk is stored in /data/app/com.k2g.leaveDemo-1.apk.
I am not sure what am I missing.
I always have to reset my device to get rid of these apps :(
Do I need to do sign something?
Do I need to do something in debug mode?
Or does it depend on the version?
I am using Samsung S2.
I assume that you enable developer mode on your android device and you are connected to your device and you have shell access (adb shell).
Once this is done you can uninstall application with this command pm uninstall --user 0 <package.name>. Where 0 is ID of main user in Android system. This way you don't need to root your device.
Here is an example how I did on my Huawei p10 lite device.
# gain shell access
$ adb shell
# check who you are
$ whoami
shell
# obtain user id
$ id
uid=2000(shell) gid=2000(shell)
# list packages
$ pm list packages | grep google
package:com.google.android.youtube
package:com.google.android.ext.services
package:com.google.android.googlequicksearchbox
package:com.google.android.onetimeinitializer
package:com.google.android.ext.shared
package:com.google.android.apps.docs.editors.sheets
package:com.google.android.configupdater
package:com.google.android.marvin.talkback
package:com.google.android.apps.tachyon
package:com.google.android.instantapps.supervisor
package:com.google.android.setupwizard
package:com.google.android.music
package:com.google.android.apps.docs
package:com.google.android.apps.maps
package:com.google.android.webview
package:com.google.android.syncadapters.contacts
package:com.google.android.packageinstaller
package:com.google.android.gm
package:com.google.android.gms
package:com.google.android.gsf
package:com.google.android.tts
package:com.google.android.partnersetup
package:com.google.android.videos
package:com.google.android.feedback
package:com.google.android.printservice.recommendation
package:com.google.android.apps.photos
package:com.google.android.syncadapters.calendar
package:com.google.android.gsf.login
package:com.google.android.backuptransport
package:com.google.android.inputmethod.latin
# uninstall google play services (warning: take backup first!)
pm uninstall --user 0 com.google.android.gms
Yes, mobile device management would bring its own problems, but i bet 'Failure' is a dos2unix problem. On my Linux machines, adb is appending a DOS newline which causes 'Failure' because uninstall thinks the CR character is part of the package name. Also remove '-1.apk' from the end of the package-1.apk filename.
adb root
adb shell
pm list packages
pm uninstall com.android.chrome
In my case, i have a phone that is in permanent 'Safe mode' so only apps under /system/app/ have a chance of running. So i install them to get the .apk files copied off, then uninstall in bulk and copy to /system/app/, wipe the /cache and reboot. Now i have more apps running even though in safe mdoe.
# adb root
# pm list packages -3 > /root/bulkuninstall.txt
# vi /root/bulkuninstall.txt and check ^M characters at end of each line.
If ^M, then must run dos2unix /root/bulkuninstall.txt.
Remove '-1.apk' using vi search and replace:
:%s/-1\.apk//g
Or sed...
# cp /data/app/* /storage/sdcard1/APKs/
# for f in `cat /root/bulkuninstall.txt`; do echo $f; pm uninstall $f; done;
#
# echo Now remount system and copy the APK files to /system/app/
# mount | grep system
# mount -o remount,rw /dev/block/(use block device from previous step) /system
# cp /storage/sdcard1/APKs/* /system/app/
# reboot
wipe cache
power on.
This is not an exact answer, but if you're looking to uninstall the app because you have an updated .apk to install, you can try this:
adb install -r yourapp.apk
The -r option tells adb to reinstall the app
If it is an Android internal app you may need to:
adb shell
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
rm /system/app/your_app
rm /data/data/your_app
remove any entries in /data/system/packages.xml
remove any entries in /data/system/packages.list
edit AndroidManifest.xml and get rid of android:sharedUserId="android.uid.shared"
This is at your own risk;-|, try in emulator first...
Just run ADB and use the following command:
adb shell pm uninstall -k --user 0 <package name>
And you should get this return:
successful
okey I was in same situation I tried all of this without result.. and the last answer was close.. I got it doing the follow:
in order to get the right name of your package do the follow:
adb shell pm list packages | grep "name of your app here"
you should see the right name of your app.. so now this one just works:
adb uninstall com.your-real-app-name
finally the command run works again:
ionic run android
Seems like you have an app that contains a hidden Device Administrator like this one here: http://www.symantec.com/security_response/writeup.jsp?docid=2013-060411-4146-99
you can only uninstall such an app when you disable the device admin first. You can use https://play.google.com/store/apps/details?id=com.trendmicro.mtrt.hiddenDAcleaner to disable it or do it by your own by sending the intent to the app that invokes the receiver that will disable the device admin.
I find that adb shell pm uninstall <package> works consistently, where adb uninstall <package> does not.
Try disable "Instant run" from settings window
Open your application Manifest and check the application's package first.
After that, be sure that your device is set into debugger mode.
Check if ADB can interact with your device:
adb devices
If your device is listed, then run:
adb uninstall PACKAGE_WRITTEN_IN_MANIFEST
Maybe you're trying to uninstall an app that is a phone administrator.
To be able to uninstall it, go to Seetings > Security > Phone Administrators.
If the app is listed, uncheck it and confirm the operation.
After that, you should be able to uninstall it using the App settings area or adb.
You should have to manually delete apps. got to Setting-> Application Management -> Running application, tap on it and you can remove, stop apps from there.
This worked for me:
This is the directory where all the APKs are stored:
cd /system/app
List them:
ls
Choose one to remove.
pm install -r <app_to_remove>.apk
Example:
$ pm install -r Google-Play-services.apk
pkg: Google-Play-services.apk
Success
I noticed that I get failure if the application I'm trying to remove is running, so kill it first.
Also, I noticed you might have to run (on a rooted device):
$ su
# mount -o remount +rw /
In my case I often get this issue when I first complise a app in debug mode and later try to install the google signed app.
That is because both apps have the same package name but diffent signatures.
Since I upgraded to Android lollypop I sometimes even get this error if I uninstall the app via the settings\Apps.
If you have this problem check if the app is installed in a other User profile and uninstall it in all user accounts.
If you have problems uninstalling through adb, I can recommend the following tool:
https://github.com/patrickfav/uber-adb-tools
you can use wildcards and supports multiple devices, also has some better error handling than the vanilla ADB (but uses it in background of course). Will work on your platform.
Full disclaimer: I am the developer
Make sure you enter the full package name with application name:
com.domain.app
I had a instance of an emulator running and a device connected.
When I ran command `adb -d uninstall PACKAGE_NAME', I got an error 'DELETE_FAILED_INTERNAL_ERROR' but when I killed the Emulator instance, I got a 'success' in un-installation process.
It can be something as simple as typing the package name in the wrong case...
I had the same problem - turned out I was entering the package name in all lower case when the actual package name included upper case characters.
adb uninstall -k <packageName - eg. com.test.app>
( If you're explicitly uninstalling you probably don't want the -k which keeps the app data and cache directories around. )
You can follow below steps to uninstall the app from the device via command prompt.
execute the command : adb -s [devicename] uninstall -k [packagename].
this command will retain the data and cache in the device but will remove the app from the device.
To remove the data and cache also from the device along with the application execute the command below.
adb shell pm uninstall -k [packagename].
if it shows sucess your app is uninstalled successfully'
If You use Xiomi Device then You need to Login in MI Account.
After Successful Registration you can install and Uninstall via ADB.
You have the name of the apk and not the package name:
You should first know the package name. Fot this tape:
adb shell pm list packages
Once you have the package name (be carefull, package name is like com.intel.... and not package:com.intel...), tape:
adb shell pm uninstall -k "package_name"
and Bingo!
In my case this was happening because I was trying to uninstall the wrong APK. I didn't realize that my bundleId had appended .demo to the ID.
I had a failure when using adb shell uninstall com.package.app/
removed / (so adb shell uninstall com.package.app) and it works
Try disable "Instant run" from Preference!
It's working for me.

Categories

Resources