This article mainly introduces how to uninstall an App by using Python scripts and ADB commands. The Complete Sample code is provided in this article, which is of reference value to everyone, if you need it, let's take a look.
Preface
This article implements a Python script to uninstall the apps on the simulator or physical machine in batches and clear the LogCat cache.
Android developers, simulators, or mobile phones often have a large number of debugging demos, which are good for mobile phones. However, simulators may cause a reduction in debugging speed and startup speed. In addition, it is difficult to delete apps one by one in the simulator. Using the ADB command, we can do a lot of things, including batch operation simulators or apps on mobile phones. Of course, this includes the delete operation. With the Python script, the ADB shell command, and the CMD window that comes with the AS, we can condense all of this into a command line.
Core code
# Delete all APPdef delAllapp (): print 'start delete all your app in your Phone or Simulator 'OS. popen ('adb wait-for-device'); corename = raw_input ("input your app package corename:") oriPackages = OS. popen ('adb shell pm list packages {name }'. format (name = corename); # list all PackageName for oriPackage in oriPackages: deletePackage = oriPackage. split (':') [1] OS. popen ('adb uninstall' + deletePackage); print deletePackage + "is deleted" # delete all the specified APPdef listAllpackage (): I = 0 OS. popen ('adb wait-for-device'); corename = raw_input ("input your app package corename:") oriPackages = OS. popen ('adb shell pm list packages {name }'. format (name = corename); for oriPackage in oriPackages: deletePackage = oriPackage. split (':') [1] print str (I) + ":" + deletePackage deleteList. append (deletePackage) I + = 1 # Delete the specified Appdef deleteApp (number): OS. popen ('adb uninstall' + deleteList [number]); print 'delete' + deleteList [number] + "success" # clear the LogCat cache def clearLogcat (): print 'start clear logcat buffer in your Phone or simulator' OS. popen ('adb wait-for-device'); OS. popen ('adb logcat-c'); print 'logcat is cleared success'
Effect implementation
Make sure your AS can use the ADB command
Configure the Python 2.7 Environment (3 + should be okay)
Find the current script path input in the CMD provided by: python unistall.py
Enter the core keywords of the package you want to delete the App according to the command prompt, such:com.example.RxCacheDemo
, Enter example (this configuration should be the same for everyone's)
After the preceding steps are completed, a message indicating whether the deletion is successful or not is displayed.
For more information about how to uninstall an App using Python scripts and ADB commands, see PHP!