{"record":{"id":"f2636ec186f82bd3","repo":"MuntashirAkon/AppManager","slug":"manifest-has-duplicate-application-tags","errorCode":null,"errorMessage":"\"manifest\" has duplicate \"application\" tags.","messagePattern":"\"manifest\" has duplicate \"application\" tags\\.","errorType":"exception","errorClass":"ApkFile.ApkFileException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/apk/ApkUtils.java","lineNumber":247,"sourceCode":"            Iterator<ResXmlAttribute> attrIt = resManifestElement.getAttributes();\n            ResXmlAttribute attr;\n            String attrName;\n            while (attrIt.hasNext()) {\n                attr = attrIt.next();\n                attrName = attr.getName();\n                if (TextUtils.isEmpty(attrName)) {\n                    continue;\n                }\n                manifestAttrs.put(attrName, attr.getValueAsString());\n            }\n            // application\n            ResXmlElement resApplicationElement = null;\n            Iterator<ResXmlElement> resXmlElementIt = resManifestElement.getElements(\"application\");\n            if (resXmlElementIt.hasNext()) {\n                resApplicationElement = resXmlElementIt.next();\n            }\n            if (resXmlElementIt.hasNext()) {\n                throw new ApkFile.ApkFileException(\"\\\"manifest\\\" has duplicate \\\"application\\\" tags.\");\n            }\n            if (resApplicationElement == null) {\n                Log.w(TAG, \"No application tag found while parsing APK.\");\n                return manifestAttrs;\n            }\n            attrIt = resApplicationElement.getAttributes();\n            while (attrIt.hasNext()) {\n                attr = attrIt.next();\n                attrName = attr.getName();\n                if (TextUtils.isEmpty(attrName)) {\n                    continue;\n                }\n                if (manifestAttrs.containsKey(attrName)) {\n                    Log.w(TAG, \"Ignoring invalid attribute in the application tag: \" + attrName);\n                    continue;\n                }\n                manifestAttrs.put(attrName, attr.getValueAsString());\n            }","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/apk/ApkUtils.java#L229-L265","documentation":"ApkUtils.getManifestAttributes parses the binary AndroidManifest.xml of an APK and expects exactly one <application> element under the root <manifest>. When a second <application> element is found (the iterator still has more entries after the first), it throws ApkFile.ApkFileException. A well-formed APK can only declare one application tag; duplicates indicate a malformed or tampered manifest.","triggerScenarios":"Calling ApkUtils.getManifestAttributes on an APK whose binary AndroidManifest.xml contains two or more <application> elements. Typically occurs when analyzing manually rebuilt, patched, or re-compiled APKs where manifest merging produced duplicate application tags.","commonSituations":"Inspecting APKs produced by broken merge tools, maliciously repackaged APKs, or APKs assembled by concatenating manifests (e.g. improper split-APK merging or smali re-build toolchains).","solutions":["Verify the APK's AndroidManifest.xml with aapt dump badging or apkanalyzer to confirm duplicate <application> tags.","Rebuild the APK with a correct single <application> element (fix the manifest merger / build config).","If merging splits, use a merge tool that deduplicates the application tag instead of concatenating manifests.","Wrap the call in try-catch for ApkFile.ApkFileException and reject the APK as malformed."],"exampleFix":"// before\nMap<String, String> attrs = ApkUtils.getManifestAttributes(apkFile);\n// after\ntry {\n    Map<String, String> attrs = ApkUtils.getManifestAttributes(apkFile);\n} catch (ApkFile.ApkFileException e) {\n    throw new IOException(\"Malformed APK: \" + e.getMessage(), e);\n}","handlingStrategy":"try-catch","validationCode":"// Pre-check: count application elements before full parse\nint appTags = Collections.list(manifestElement.getElements(\"application\")).size();\nif (appTags != 1) throw new IOException(\"Expected 1 application tag, found \" + appTags);","typeGuard":null,"tryCatchPattern":"try {\n    Map<String, String> attrs = ApkUtils.getManifestAttributes(apkFile);\n} catch (ApkFile.ApkFileException e) {\n    Log.e(TAG, \"Malformed manifest: duplicate application tag\", e);\n}","preventionTips":["Only parse APKs built by trusted toolchains; reject repackaged/merged APKs up front.","Sanity-check manifests with aapt dump badging before programmatic parsing.","Treat manifest exceptions as a signal the APK is tampered or corrupt and quarantine it."],"tags":["apk","manifest","parsing","android"],"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-14T11:17:12.474Z"}