Skip to content

Commit 3a73f48

Browse files
authored
do uninstall only when that app is installed (#451)
1 parent 727d60e commit 3a73f48

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

bin/cocos.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,15 @@ def get_xcode_version():
717717

718718
return version
719719

720+
def app_is_installed(adb_cmd, pack_name):
721+
list_pack_cmd = "%s shell 'pm list packages'" % (adb_cmd)
722+
desired_name = "package:%s" % (pack_name)
723+
child = subprocess.Popen(list_pack_cmd, stdout=subprocess.PIPE, shell=True)
724+
for line in child.stdout:
725+
if desired_name == line.strip():
726+
return True
727+
return False
728+
720729
def version_compare(a, op, b):
721730
'''Compares two version numbers to see if a op b is true
722731

plugins/plugin_deploy.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,10 @@ def deploy_android(self, dependencies):
161161
adb_path = cocos.CMDRunner.convert_path_to_cmd(os.path.join(sdk_root, 'platform-tools', 'adb'))
162162

163163
if not self._no_uninstall:
164-
#TODO detect if the application is installed before running this
165-
adb_uninstall = "%s uninstall %s" % (adb_path, self.package)
166-
self._run_cmd(adb_uninstall)
164+
# do uninstall only when that app is installed
165+
if cocos.app_is_installed(adb_path, self.package):
166+
adb_uninstall = "%s uninstall %s" % (adb_path, self.package)
167+
self._run_cmd(adb_uninstall)
167168

168169
adb_install = "%s install -r \"%s\"" % (adb_path, apk_path)
169170
self._run_cmd(adb_install)

0 commit comments

Comments
 (0)