diff --git a/tools/aapt2/compile/InlineXmlFormatParser.cpp b/tools/aapt2/compile/InlineXmlFormatParser.cpp index 857cdd5365a0c..73a90da6baf08 100644 --- a/tools/aapt2/compile/InlineXmlFormatParser.cpp +++ b/tools/aapt2/compile/InlineXmlFormatParser.cpp @@ -146,6 +146,10 @@ bool InlineXmlFormatParser::Consume(IAaptContext* context, xml::XmlResource* doc } else { new_doc->root.reset(static_cast(child.release())); new_doc->root->parent = nullptr; + // Copy down the namespace declarations + new_doc->root->namespace_decls = doc->root->namespace_decls; + // Recurse for nested inlines + Consume(context, new_doc.get()); } } diff --git a/tools/aapt2/compile/InlineXmlFormatParser_test.cpp b/tools/aapt2/compile/InlineXmlFormatParser_test.cpp index de7739ada407a..a4c602c29b860 100644 --- a/tools/aapt2/compile/InlineXmlFormatParser_test.cpp +++ b/tools/aapt2/compile/InlineXmlFormatParser_test.cpp @@ -137,4 +137,47 @@ TEST(InlineXmlFormatParserTest, ExtractTwoXmlResources) { EXPECT_THAT(extracted_doc_drawable->root->name, StrEq("vector")); } +TEST(InlineXmlFormatParserTest, ExtractNestedXmlResources) { + std::unique_ptr context = test::ContextBuilder().Build(); + std::unique_ptr doc = test::BuildXmlDom(R"( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + )"); + + doc->file.name = test::ParseNameOrDie("layout/main"); + + InlineXmlFormatParser parser; + ASSERT_TRUE(parser.Consume(context.get(), doc.get())); + // Confirm that all of the nested inline xmls are parsed out. + ASSERT_THAT(parser.GetExtractedInlineXmlDocuments(), SizeIs(8u)); +} } // namespace aapt