Preface
This article implements a Python script to batch uninstall apps on the simulator or physical machine and clear the LogCat cache.
Friends who develop Android, there are often a large number of debugging demos in the simulator or mobile phone. This is fine for mobile phones, but for the simulator, it may cause a decrease in debugging speed and startup speed. Moreover, it is very troublesome to delete apps one by one in the simulator. Using ADB commands, we can do many things, including batch operations on the simulator or apps on the mobile phone. Of course, this includes deletion operations. Using Python scripts, ADB shell commands and the CMD window that comes with AS, we can condense all this into a command line.
Core code
# 删除所有你指定包名的 APP def 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" # 删除所有你指定包名的特定 APP def 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 # 删除指定 App def deleteApp(number): os.popen('adb uninstall ' + deleteList[number] ); print 'delete '+ deleteList[number] + "success" # 清除 LogCat 缓存 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
##How to use
python unistall.py
com.example.RxCacheDemo, just enter example (this configuration of everyone's AS should be the same)