From 55f2761fc8afdff01e75bce2718c222912a125f7 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Mon, 24 Jul 2017 17:08:32 -0700 Subject: [PATCH] AAPT2: Add targetConfig to AndroidManifest.xml Splits may include more/different configurations than they were originally specified to include. This happens, for instance, when a particular requested density doesn't exist. A fallback density resource is chosen for the split. This makes programmatic configuration targetting difficult, as the APK may report that it has resources for multiple densities, while it was meant to target only a specific density. This change encodes a comma separated list of the intended configurations for the split in an attribute called 'targetConfig' on the tag of AndroidManifest.xml. Test: manual Change-Id: I3167e9341a434abc34ed2ddb8f740762b40b1ab7 --- tools/aapt2/cmd/Util.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/aapt2/cmd/Util.cpp b/tools/aapt2/cmd/Util.cpp index 8741b7b678ecf..e1c45d68f6115 100644 --- a/tools/aapt2/cmd/Util.cpp +++ b/tools/aapt2/cmd/Util.cpp @@ -179,6 +179,13 @@ std::unique_ptr GenerateSplitManifest(const AppInfo& app_info, xml::Attribute{"", "configForSplit", app_info.split_name.value()}); } + // Splits may contain more configurations than originally desired (fallback densities, etc.). + // This makes programmatic discovery of split targetting difficult. Encode the original + // split constraints intended for this split. + std::stringstream target_config_str; + target_config_str << util::Joiner(constraints.configs, ","); + manifest_el->attributes.push_back(xml::Attribute{"", "targetConfig", target_config_str.str()}); + std::unique_ptr application_el = util::make_unique(); application_el->name = "application"; application_el->attributes.push_back(