Correctly insert platformBuildVersionCode/Name
AAPT(1) encodes platformBuildVersionCode and
platformBuildVersionName into the manifest along with
compileSdkVersion and compileSdkVersionCodename. AAPT2 was extracting
the platform attributes from the app being created rather than the
framework.
This change inserts the correct platform attributes.
Bug: 124227171
Test: aapt2_tests
Change-Id: I4bc7986d25f065cecf01b9e988de4d37283ef7de
diff --git a/tools/aapt2/link/ManifestFixer.cpp b/tools/aapt2/link/ManifestFixer.cpp
index 85bf6f2..582a5b8 100644
--- a/tools/aapt2/link/ManifestFixer.cpp
+++ b/tools/aapt2/link/ManifestFixer.cpp
@@ -294,22 +294,6 @@
}
}
- if (el->FindAttribute("", "platformBuildVersionCode") == nullptr) {
- auto versionCode = el->FindAttribute(xml::kSchemaAndroid, "versionCode");
- if (versionCode != nullptr) {
- el->attributes.push_back(xml::Attribute{"", "platformBuildVersionCode",
- versionCode->value});
- }
- }
-
- if (el->FindAttribute("", "platformBuildVersionName") == nullptr) {
- auto versionName = el->FindAttribute(xml::kSchemaAndroid, "versionName");
- if (versionName != nullptr) {
- el->attributes.push_back(xml::Attribute{"", "platformBuildVersionName",
- versionName->value});
- }
- }
-
return true;
});
@@ -489,8 +473,14 @@
// Make sure we un-compile the value if it was set to something else.
attr->compiled_value = {};
-
attr->value = options_.compile_sdk_version.value();
+
+ attr = root->FindOrCreateAttribute("", "platformBuildVersionCode");
+
+ // Make sure we un-compile the value if it was set to something else.
+ attr->compiled_value = {};
+ attr->value = options_.compile_sdk_version.value();
+
}
if (options_.compile_sdk_version_codename) {
@@ -499,7 +489,12 @@
// Make sure we un-compile the value if it was set to something else.
attr->compiled_value = {};
+ attr->value = options_.compile_sdk_version_codename.value();
+ attr = root->FindOrCreateAttribute("", "platformBuildVersionName");
+
+ // Make sure we un-compile the value if it was set to something else.
+ attr->compiled_value = {};
attr->value = options_.compile_sdk_version_codename.value();
}