summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Adam Lesinski <adamlesinski@google.com> 2017-10-26 17:18:19 -0700
committer Adam Lesinski <adamlesinski@google.com> 2017-10-26 17:18:19 -0700
commit461c80573b0ef0447f8757f1c32ae9e9be85c9b8 (patch)
tree8b582c8ce33280f1e1e0457b2bdce80e77b7a6f1
parent4f340a4f8b50b29b562407e39563ee78a90bea3f (diff)
AAPT2: Fix issue where generated XML would be tagged with UNKNOWN type
CompiledFiles with UNKNOWN type are copied through, leading to protobuf outputs in the final APK. Test: make aapt2_tests Change-Id: Ia0c464caa3951ff27436d1d50c2a8555bc89302b
-rw-r--r--tools/aapt2/compile/InlineXmlFormatParser.cpp9
-rw-r--r--tools/aapt2/compile/InlineXmlFormatParser_test.cpp4
2 files changed, 9 insertions, 4 deletions
diff --git a/tools/aapt2/compile/InlineXmlFormatParser.cpp b/tools/aapt2/compile/InlineXmlFormatParser.cpp
index a17926067a0b..99b4c31884bb 100644
--- a/tools/aapt2/compile/InlineXmlFormatParser.cpp
+++ b/tools/aapt2/compile/InlineXmlFormatParser.cpp
@@ -118,10 +118,11 @@ bool InlineXmlFormatParser::Consume(IAaptContext* context, xml::XmlResource* doc
size_t name_suffix_counter = 0;
for (const InlineDeclaration& decl : visitor.GetInlineDeclarations()) {
- auto new_doc = util::make_unique<xml::XmlResource>();
- new_doc->file.config = doc->file.config;
- new_doc->file.source = doc->file.source.WithLine(decl.el->line_number);
- new_doc->file.name = doc->file.name;
+ // Create a new XmlResource with the same ResourceFile as the base XmlResource.
+ auto new_doc = util::make_unique<xml::XmlResource>(doc->file);
+
+ // Attach the line number.
+ new_doc->file.source.line = decl.el->line_number;
// Modify the new entry name. We need to suffix the entry with a number to
// avoid local collisions, then mangle it with the empty package, such that it won't show up
diff --git a/tools/aapt2/compile/InlineXmlFormatParser_test.cpp b/tools/aapt2/compile/InlineXmlFormatParser_test.cpp
index de7739ada407..d6d734d395b5 100644
--- a/tools/aapt2/compile/InlineXmlFormatParser_test.cpp
+++ b/tools/aapt2/compile/InlineXmlFormatParser_test.cpp
@@ -54,6 +54,7 @@ TEST(InlineXmlFormatParserTest, ExtractOneXmlResource) {
</View1>)");
doc->file.name = test::ParseNameOrDie("layout/main");
+ doc->file.type = ResourceFile::Type::kProtoXml;
InlineXmlFormatParser parser;
ASSERT_TRUE(parser.Consume(context.get(), doc.get()));
@@ -81,6 +82,9 @@ TEST(InlineXmlFormatParserTest, ExtractOneXmlResource) {
// Make sure the generated reference is correct.
EXPECT_THAT(extracted_doc->file.name, Eq(name_ref));
+ // Make sure the ResourceFile::Type is the same.
+ EXPECT_THAT(extracted_doc->file.type, Eq(ResourceFile::Type::kProtoXml));
+
// Verify the structure of the extracted XML.
el = extracted_doc->root.get();
ASSERT_THAT(el, NotNull());