Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python script to reinstall an apk
import subprocess
import sys
import re
apkpath = sys.argv[1]
print('checking packagename')
head = subprocess.check_output('aapt d badging "' + apkpath + '"').decode("utf-8").split("\n")[0]
packagename = re.match(r'^package: name=\'([A-Za-z0-9\.]+)\'', head).group(1)
print('uninstalling ' + packagename)
subprocess.check_call("adb uninstall " + packagename)
print('installing ' + apkpath)
subprocess.check_call('adb install "' + apkpath + '"')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment