diff --git a/jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java b/jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java index c0df3b6276c..bafdb5d1904 100644 --- a/jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java +++ b/jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java @@ -40,6 +40,7 @@ public class BinaryXMLParser extends CommonBinaryParser { private final Map resNames; private Map nsMap; private Set nsMapGenerated; + private Set definedNamespaces; private final Map tagAttrDeobfNames = new HashMap<>(); private ICodeWriter writer; @@ -78,11 +79,13 @@ public synchronized ICodeInfo parse(InputStream inputStream) throws IOException } nsMapGenerated = new HashSet<>(); nsMap = new HashMap<>(); + definedNamespaces = new HashSet<>(); writer = rootNode.makeCodeWriter(); writer.add(""); firstElement = true; decode(); nsMap = null; + definedNamespaces = null; ICodeInfo codeInfo = writer.finish(); this.classNameCache = null; // reset class name cache return codeInfo; @@ -269,15 +272,18 @@ private void parseElement() throws IOException { int idIndex = is.readInt16(); int classIndex = is.readInt16(); int styleIndex = is.readInt16(); - if ("manifest".equals(currentTag) || writer.getIndent() == 0) { + if ("manifest".equals(currentTag) || definedNamespaces.size() != nsMap.size()) { for (Map.Entry entry : nsMap.entrySet()) { - String nsValue = getValidTagAttributeName(entry.getValue()); - writer.add(" xmlns"); - if (nsValue != null && !nsValue.trim().isEmpty()) { - writer.add(':'); - writer.add(nsValue); + if (!definedNamespaces.contains(entry.getKey())) { + definedNamespaces.add(entry.getKey()); + String nsValue = getValidTagAttributeName(entry.getValue()); + writer.add(" xmlns"); + if (nsValue != null && !nsValue.trim().isEmpty()) { + writer.add(':'); + writer.add(nsValue); + } + writer.add("=\"").add(StringUtils.escapeXML(entry.getKey())).add('"'); } - writer.add("=\"").add(StringUtils.escapeXML(entry.getKey())).add('"'); } } boolean attrNewLine = attributeCount != 1 && this.attrNewLine;