{"record":{"id":"503559bf488cf15d","repo":"MuntashirAkon/AppManager","slug":"manifest-has-duplicate-application-tags-manifestparser","errorCode":null,"errorMessage":"\"manifest\" has duplicate \"application\" tags.","messagePattern":"\"manifest\" has duplicate \"application\" tags\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/apk/parser/ManifestParser.java","lineNumber":81,"sourceCode":"            xmlBlock.setPackageBlock(AndroidBinXmlDecoder.getFrameworkPackageBlock());\n            ResXmlElement resManifestElement = xmlBlock.getDocumentElement();\n            // manifest\n            if (!TAG_MANIFEST.equals(resManifestElement.getName())) {\n                throw new IOException(\"\\\"manifest\\\" tag not found.\");\n            }\n            String packageName = getAttributeValue(resManifestElement, ATTR_MANIFEST_PACKAGE);\n            if (packageName == null) {\n                throw new IOException(\"\\\"manifest\\\" does not have required attribute \\\"package\\\".\");\n            }\n            mPackageName = packageName;\n            // manifest -> application\n            ResXmlElement resApplicationElement = null;\n            Iterator<ResXmlElement> resXmlElementIt = resManifestElement.getElements(TAG_APPLICATION);\n            if (resXmlElementIt.hasNext()) {\n                resApplicationElement = resXmlElementIt.next();\n            }\n            if (resXmlElementIt.hasNext()) {\n                throw new IOException(\"\\\"manifest\\\" has duplicate \\\"application\\\" tags.\");\n            }\n            if (resApplicationElement == null) {\n                Log.i(TAG, \"package %s does not have \\\"application\\\" tag.\", mPackageName);\n                return Collections.emptyList();\n            }\n            // manifest -> application -> component\n            List<ManifestComponent> componentIfList = new ArrayList<>(resApplicationElement.getElementsCount());\n            String tagName;\n            resXmlElementIt = resApplicationElement.getElements();\n            while (resXmlElementIt.hasNext()) {\n                ResXmlElement elem = resXmlElementIt.next();\n                tagName = elem.getName();\n                if (tagName != null) {\n                    switch (tagName) {\n                        case TAG_ACTIVITY:\n                        case TAG_ACTIVITY_ALIAS:\n                        case TAG_SERVICE:\n                        case TAG_RECEIVER:","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/apk/parser/ManifestParser.java#L63-L99","documentation":"ManifestParser throws this while walking the binary AndroidManifest XML: the <manifest> root contains more than one <application> element. A valid manifest must have exactly zero or one <application> tag, so a second occurrence means a malformed/recompiled manifest and parsing cannot continue unambiguously.","triggerScenarios":"Calling parseComponents (via manifestComponents) on an APK whose binary manifest contains two <application> elements under <manifest>; the iterator over TAG_APPLICATION elements returns a second element.","commonSituations":"Corrupt or hand-patched APKs, bad recompiles with apktool, maliciously modified manifests, or overlays/merges that duplicated the application tag.","solutions":["Inspect the binary manifest with aapt dump xmltree and remove/merge the duplicate <application> element, then rebuild the APK","Use apktool to decode, fix AndroidManifest.xml to a single <application>, and rebuild/sign","Obtain a clean copy of the APK from a trusted source","If you control the build, check manifest merger output for duplicated application nodes"],"exampleFix":"// before: parsing unverified APK directly\nList<ManifestComponent> comps = new ManifestParser(apk).manifestComponents();\n// after\ntry {\n    List<ManifestComponent> comps = new ManifestParser(apk).manifestComponents();\n} catch (IOException e) {\n    Log.w(TAG, \"Malformed manifest, skipping APK: \" + e.getMessage());\n}","handlingStrategy":"try-catch","validationCode":"// Pre-check with aapt/apktool before parsing:\n// aapt dump xmltree app.apk AndroidManifest.xml | grep -c '<application>'\n// if count > 1, treat APK as malformed.","typeGuard":"boolean hasDuplicateApplication(byte[] manifestXml) {\n    // decode binary XML and count TAG_APPLICATION elements under root\n    return countElements(manifestXml, \"application\") > 1;\n}","tryCatchPattern":"try {\n    List<ManifestComponent> comps = parser.manifestComponents();\n} catch (IOException e) {\n    if (e.getMessage().contains(\"duplicate \\\"application\\\" tags\")) {\n        // mark APK as malformed and skip\n    }\n}","preventionTips":["Never hand-edit binary manifests; recompile from source","Validate APKs with apksmith/apktool before batch processing","Treat aapt warnings about duplicated elements as build errors"],"tags":["android","apk-parser","manifest","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}