summaryrefslogtreecommitdiff
path: root/tools/aapt2/configuration/ConfigurationParser.cpp
diff options
context:
space:
mode:
authorShane Farmer <safarmer@google.com>2017-09-21 14:37:44 -0700
committerShane Farmer <safarmer@google.com>2017-10-03 16:13:04 +0000
commit810fd184356a76fc0fa35d07212df10b7e058063 (patch)
treee498746de043cc4a0cfbbdf7057275ee519e471d /tools/aapt2/configuration/ConfigurationParser.cpp
parent3edd47264335cf609ac6e733db77522f7c959c3f (diff)
AAPT2: Update versionCode in multi-APKs.
Set versionCode in the AndroidManifest.xml so each artifact has a unique version code. This will allow the play store to serve up the correct APKs. The versionCode is determined by taking the versionCode from the input APK and adding the configured version to that. If an artifact does not have a version, the next version is used based on the order in the configuration file. If the firs artifact does not have a version, it starts at 1, so that all artifacts have a different version code to the base APK. Bug: 64972562 Test: unit tests Test: manually optimized an APK into multiple APKs and confirmed versions: aapt dump badging ${apk} | grep versionCode Change-Id: Ie12b3e42bbd8ce9a2819712c2c56b24c0a901e6b
Diffstat (limited to 'tools/aapt2/configuration/ConfigurationParser.cpp')
-rw-r--r--tools/aapt2/configuration/ConfigurationParser.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/aapt2/configuration/ConfigurationParser.cpp b/tools/aapt2/configuration/ConfigurationParser.cpp
index d2b4d725c416..a79a577c663b 100644
--- a/tools/aapt2/configuration/ConfigurationParser.cpp
+++ b/tools/aapt2/configuration/ConfigurationParser.cpp
@@ -330,15 +330,32 @@ Maybe<PostProcessingConfiguration> ConfigurationParser::Parse() {
// TODO: Validate all references in the configuration are valid. It should be safe to assume from
// this point on that any references from one section to another will be present.
+ // TODO: Automatically arrange artifacts so that they match Play Store multi-APK requirements.
+ // see: https://developer.android.com/google/play/publishing/multiple-apks.html
+ //
+ // For now, make sure the version codes are unique.
+ std::vector<Artifact>& artifacts = config.artifacts;
+ std::sort(artifacts.begin(), artifacts.end());
+ if (std::adjacent_find(artifacts.begin(), artifacts.end()) != artifacts.end()) {
+ diag_->Error(DiagMessage() << "Configuration has duplicate versions");
+ return {};
+ }
+
return {config};
}
ConfigurationParser::ActionHandler ConfigurationParser::artifact_handler_ =
[](PostProcessingConfiguration* config, Element* root_element, IDiagnostics* diag) -> bool {
+ // This will be incremented later so the first version will always be different to the base APK.
+ int current_version = (config->artifacts.empty()) ? 0 : config->artifacts.back().version;
+
Artifact artifact{};
+ Maybe<int> version;
for (const auto& attr : root_element->attributes) {
if (attr.name == "name") {
artifact.name = attr.value;
+ } else if (attr.name == "version") {
+ version = std::stoi(attr.value);
} else if (attr.name == "abi-group") {
artifact.abi_group = {attr.value};
} else if (attr.name == "screen-density-group") {
@@ -356,6 +373,9 @@ ConfigurationParser::ActionHandler ConfigurationParser::artifact_handler_ =
<< attr.value);
}
}
+
+ artifact.version = (version) ? version.value() : current_version + 1;
+
config->artifacts.push_back(artifact);
return true;
};