From 99aca2543835d56001eec63ce60e6c7dc73a4570 Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Mon, 9 Oct 2017 18:30:06 +0100 Subject: [PATCH] ApkInfo: Improve error for bad .apk files Provide a more specific error, including the output from aapt. --- devlib/utils/android.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/devlib/utils/android.py b/devlib/utils/android.py index ce1ab0b..0cdd2b0 100644 --- a/devlib/utils/android.py +++ b/devlib/utils/android.py @@ -135,7 +135,11 @@ class ApkInfo(object): _check_env() command = [aapt, 'dump', 'badging', apk_path] logger.debug(' '.join(command)) - output = subprocess.check_output(command) + try: + output = subprocess.check_output(command, stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as e: + raise HostError('Error parsing APK file {}. `aapt` says:\n{}' + .format(apk_path, e.output)) for line in output.split('\n'): if line.startswith('application-label:'): self.label = line.split(':')[1].strip().replace('\'', '')