From 9f6dec11e6fe003609f4c5908d3a965b1f196c47 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Fri, 20 Apr 2018 12:29:29 -0700 Subject: [PATCH] Allow overriding the compile SDK We automatically pull the compile SDK from the platform. But, in certain circumstances the platform's SDK codename is incorrect. Allow the name to be overridden on the command line. Change-Id: I398f1b00b29db42e4ce202b94cda483c98971a14 Fixes: 78324052 Test: ./out/host/linux-x86/nativetest64/aapt2_tests/aapt2_tests --- tools/aapt2/cmd/Link.cpp | 61 ++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/tools/aapt2/cmd/Link.cpp b/tools/aapt2/cmd/Link.cpp index a3b7664818873..b90e7b3042f91 100644 --- a/tools/aapt2/cmd/Link.cpp +++ b/tools/aapt2/cmd/Link.cpp @@ -798,35 +798,39 @@ class LinkCommand { return; } - xml::Attribute* attr = manifest_xml->root->FindAttribute(xml::kSchemaAndroid, "versionCode"); - if (attr != nullptr) { - Maybe& compile_sdk_version = options_.manifest_fixer_options.compile_sdk_version; - if (BinaryPrimitive* prim = ValueCast(attr->compiled_value.get())) { - switch (prim->value.dataType) { - case Res_value::TYPE_INT_DEC: - compile_sdk_version = StringPrintf("%" PRId32, static_cast(prim->value.data)); - break; - case Res_value::TYPE_INT_HEX: - compile_sdk_version = StringPrintf("%" PRIx32, prim->value.data); - break; - default: - break; + if (!options_.manifest_fixer_options.compile_sdk_version) { + xml::Attribute* attr = manifest_xml->root->FindAttribute(xml::kSchemaAndroid, "versionCode"); + if (attr != nullptr) { + Maybe& compile_sdk_version = options_.manifest_fixer_options.compile_sdk_version; + if (BinaryPrimitive* prim = ValueCast(attr->compiled_value.get())) { + switch (prim->value.dataType) { + case Res_value::TYPE_INT_DEC: + compile_sdk_version = StringPrintf("%" PRId32, static_cast(prim->value.data)); + break; + case Res_value::TYPE_INT_HEX: + compile_sdk_version = StringPrintf("%" PRIx32, prim->value.data); + break; + default: + break; + } + } else if (String* str = ValueCast(attr->compiled_value.get())) { + compile_sdk_version = *str->value; + } else { + compile_sdk_version = attr->value; } - } else if (String* str = ValueCast(attr->compiled_value.get())) { - compile_sdk_version = *str->value; - } else { - compile_sdk_version = attr->value; } } - attr = manifest_xml->root->FindAttribute(xml::kSchemaAndroid, "versionName"); - if (attr != nullptr) { - Maybe& compile_sdk_version_codename = - options_.manifest_fixer_options.compile_sdk_version_codename; - if (String* str = ValueCast(attr->compiled_value.get())) { - compile_sdk_version_codename = *str->value; - } else { - compile_sdk_version_codename = attr->value; + if (!options_.manifest_fixer_options.compile_sdk_version_codename) { + xml::Attribute* attr = manifest_xml->root->FindAttribute(xml::kSchemaAndroid, "versionName"); + if (attr != nullptr) { + Maybe& compile_sdk_version_codename = + options_.manifest_fixer_options.compile_sdk_version_codename; + if (String* str = ValueCast(attr->compiled_value.get())) { + compile_sdk_version_codename = *str->value; + } else { + compile_sdk_version_codename = attr->value; + } } } } @@ -2102,6 +2106,13 @@ int Link(const std::vector& args, IDiagnostics* diagnostics) { .OptionalFlag("--version-name", "Version name to inject into the AndroidManifest.xml if none is present.", &options.manifest_fixer_options.version_name_default) + .OptionalFlag("--compile-sdk-version-code", + "Version code (integer) to inject into the AndroidManifest.xml if none is\n" + "present.", + &options.manifest_fixer_options.compile_sdk_version) + .OptionalFlag("--compile-sdk-version-name", + "Version name to inject into the AndroidManifest.xml if none is present.", + &options.manifest_fixer_options.compile_sdk_version_codename) .OptionalSwitch("--shared-lib", "Generates a shared Android runtime library.", &shared_lib) .OptionalSwitch("--static-lib", "Generate a static Android library.", &static_lib)