From a03f1265fba2756ae0d134cd7833ac7a32b8f8ea Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 1 Feb 2023 12:12:51 +0000 Subject: [PATCH] Support SHA minSdkVersion in APK in APEX Bug: 266903788 Test: rm -fr out/dist UNBUNDLED_BUILD_SDKS_FROM_SOURCE=true UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT=true TARGET_BUILD_APPS="com.google.android.rkpd" vendor/google/build/mainline_modules_bundles.sh # Without this change it fails, with this change it passes at # which point run the following. mkdir contents cd contents unzip ../out/dist/dev_keys_signed/com.google.android.rkpd/com.google.android.rkpd.apks deapexer extract standalones/standalone-x86.apex apex-contents aapt2 dump badging apex-contents/priv-app/rkpdapp.google@*/rkpdapp.google.apk | grep Version # The sdkVersion and targetSdkVersion should both be set to SHA # versions. Change-Id: I9ca54affd30f0a6cf561f1274b991d39e7cf1bce (cherry picked from commit 730d0c437a879bd23c80f82566bab8f8db2418ee) Merged-In: I9ca54affd30f0a6cf561f1274b991d39e7cf1bce --- tools/releasetools/common.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py index 418d8daa85..ec49b0d36f 100644 --- a/tools/releasetools/common.py +++ b/tools/releasetools/common.py @@ -2309,12 +2309,22 @@ def GetMinSdkVersionInt(apk_name, codename_to_api_level_map): try: return int(version) except ValueError: - # Not a decimal number. Codename? - if version in codename_to_api_level_map: - return codename_to_api_level_map[version] + # Not a decimal number. + # + # It could be either a straight codename, e.g. + # UpsideDownCake + # + # Or a codename with API fingerprint SHA, e.g. + # UpsideDownCake.e7d3947f14eb9dc4fec25ff6c5f8563e + # + # Extract the codename and try and map it to a version number. + split = version.split(".") + codename = split[0] + if codename in codename_to_api_level_map: + return codename_to_api_level_map[codename] raise ExternalError( - "Unknown minSdkVersion: '{}'. Known codenames: {}".format( - version, codename_to_api_level_map)) + "Unknown codename: '{}' from minSdkVersion: '{}'. Known codenames: {}".format( + codename, version, codename_to_api_level_map)) def SignFile(input_name, output_name, key, password, min_api_level=None,