From fb6312fe93a8544e6a95d1c619c8cea3940cbe1a Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Tue, 28 Jun 2016 14:40:32 -0700 Subject: AAPT2: Add version collapsing When an app specifies (or imports) resources with various configurations for different SDK versions, specifying a minSdk will make many of those resources unreachable. Version collapsing will prune out the resources specified for SDK versions less than the minSdk. If, however, there is no exact matching resource for the minSdk version, the next smallest SDK version is kept. Change-Id: Ic7bcab6c59d65c97c67c8767358abb57cdec60a4 --- tools/aapt2/ResourceUtils.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tools/aapt2/ResourceUtils.cpp') diff --git a/tools/aapt2/ResourceUtils.cpp b/tools/aapt2/ResourceUtils.cpp index a0a7efc46476..302c04fc3780 100644 --- a/tools/aapt2/ResourceUtils.cpp +++ b/tools/aapt2/ResourceUtils.cpp @@ -16,6 +16,7 @@ #include "NameMangler.h" #include "ResourceUtils.h" +#include "SdkConstants.h" #include "flatten/ResourceTypeExtensions.h" #include "util/Files.h" #include "util/Util.h" @@ -402,6 +403,21 @@ bool tryParseBool(const StringPiece16& str, bool* outValue) { return false; } +Maybe tryParseSdkVersion(const StringPiece16& str) { + StringPiece16 trimmedStr(util::trimWhitespace(str)); + android::Res_value value; + if (android::ResTable::stringToInt(trimmedStr.data(), trimmedStr.size(), &value)) { + return static_cast(value.data); + } + + // Try parsing the code name. + std::pair entry = getDevelopmentSdkCodeNameAndVersion(); + if (entry.first == trimmedStr) { + return entry.second; + } + return {}; +} + std::unique_ptr tryParseBool(const StringPiece16& str) { bool result = false; if (tryParseBool(str, &result)) { -- cgit v1.2.3-59-g8ed1b