Use the Python script and ADB command to uninstall the App, pythonadb
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
Usage
- 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.
Summary
The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.