Switch to aapt2 for getting minSdkVersion
aapt does not support parsing some referencing attributes.
Switch to latest tool, aapt2, which works better.
Test: aapt2 dump badging test.apk and returned 0.
Test: Run check_target_files_signatures.py with a target_files.zip.
Test: Run sign_target_files_apks.py with a target_files.zip.
Change-Id: Ib3a4740506f29ebab6930767f2aa8a0b5c4ba053
diff --git a/tools/releasetools/Android.bp b/tools/releasetools/Android.bp
index d4c4673..65eee94 100644
--- a/tools/releasetools/Android.bp
+++ b/tools/releasetools/Android.bp
@@ -37,7 +37,7 @@
// Only the tools that are referenced directly are listed as required modules. For example,
// `avbtool` is not here, as the script always uses the one from info_dict['avb_avbtool'].
required: [
- "aapt",
+ "aapt2",
"boot_signer",
"brotli",
"bsdiff",
diff --git a/tools/releasetools/check_target_files_signatures.py b/tools/releasetools/check_target_files_signatures.py
index 60200a3..8c1bb9a 100755
--- a/tools/releasetools/check_target_files_signatures.py
+++ b/tools/releasetools/check_target_files_signatures.py
@@ -213,7 +213,7 @@
self.certs = frozenset(out)
def ReadManifest(self, full_filename):
- p = common.Run(["aapt", "dump", "xmltree", full_filename,
+ p = common.Run(["aapt2", "dump", "xmltree", full_filename, "--file",
"AndroidManifest.xml"],
stdout=subprocess.PIPE)
manifest, err = p.communicate()
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 913601f..0594b79 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -1048,7 +1048,7 @@
def GetMinSdkVersion(apk_name):
"""Gets the minSdkVersion declared in the APK.
- It calls 'aapt' to query the embedded minSdkVersion from the given APK file.
+ It calls 'aapt2' to query the embedded minSdkVersion from the given APK file.
This can be both a decimal number (API Level) or a codename.
Args:
@@ -1061,12 +1061,12 @@
ExternalError: On failing to obtain the min SDK version.
"""
proc = Run(
- ["aapt", "dump", "badging", apk_name], stdout=subprocess.PIPE,
+ ["aapt2", "dump", "badging", apk_name], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdoutdata, stderrdata = proc.communicate()
if proc.returncode != 0:
raise ExternalError(
- "Failed to obtain minSdkVersion: aapt return code {}:\n{}\n{}".format(
+ "Failed to obtain minSdkVersion: aapt2 return code {}:\n{}\n{}".format(
proc.returncode, stdoutdata, stderrdata))
for line in stdoutdata.split("\n"):
@@ -1074,7 +1074,7 @@
m = re.match(r'sdkVersion:\'([^\']*)\'', line)
if m:
return m.group(1)
- raise ExternalError("No minSdkVersion returned by aapt")
+ raise ExternalError("No minSdkVersion returned by aapt2")
def GetMinSdkVersionInt(apk_name, codename_to_api_level_map):