Do not serialize empty text in manifest proto
When linking an APK in the proto format, the manifest is currently
serializes text nodes that only contain whitespace:
child: {
text: "\n "
source: {
line_number : 0x0000000f
column_number: 0x0000002f
}
}
These whitespace bloat the proto size unnecessarily. Do not write these
text nodes for proto apks.
Bug: 118800653
Test: make aapt2_tests
Change-Id: Icfaaf88976f81450bbf51610a316b336deeae60c
diff --git a/tools/aapt2/cmd/Link.cpp b/tools/aapt2/cmd/Link.cpp
index 6a7da0c..1b5601d 100644
--- a/tools/aapt2/cmd/Link.cpp
+++ b/tools/aapt2/cmd/Link.cpp
@@ -236,6 +236,9 @@
case OutputFormat::kProto: {
pb::XmlNode pb_node;
+ // Strip whitespace text nodes from tha AndroidManifest.xml
+ SerializeXmlOptions options;
+ options.remove_empty_text_nodes = (path == kAndroidManifestPath);
SerializeXmlResourceToPb(xml_res, &pb_node);
return io::CopyProtoToArchive(context, &pb_node, path.to_string(), ArchiveEntry::kCompress,
writer);
@@ -1543,7 +1546,7 @@
bool WriteApk(IArchiveWriter* writer, proguard::KeepSet* keep_set, xml::XmlResource* manifest,
ResourceTable* table) {
const bool keep_raw_values = context_->GetPackageType() == PackageType::kStaticLib;
- bool result = FlattenXml(context_, *manifest, "AndroidManifest.xml", keep_raw_values,
+ bool result = FlattenXml(context_, *manifest, kAndroidManifestPath, keep_raw_values,
true /*utf16*/, options_.output_format, writer);
if (!result) {
return false;