{"record":{"id":"7167ed6f4719ddf3","repo":"shwenzhang/AndResGuard","slug":"the-old-mapping-file-packagename-is-malformed-it-should-be","errorCode":null,"errorMessage":"the old mapping file packagename is malformed, it should be like com.tencent.mm.R.attr.test, yours %s\n","messagePattern":"the old mapping file packagename is malformed, it should be like com\\.tencent\\.mm\\.R\\.attr\\.test, yours (.+?)\n","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"AndResGuard-core/src/main/java/com/tencent/mm/resourceproguard/Configuration.java","lineNumber":491,"sourceCode":"\n      while (line != null) {\n        if (line.length() > 0) {\n          Matcher mat = MAP_PATTERN.matcher(line);\n\n          if (mat.find()) {\n            String nameAfter = mat.group(2);\n            String nameBefore = mat.group(1);\n            nameAfter = nameAfter.trim();\n            nameBefore = nameBefore.trim();\n\n            //如果有这个的话，那就是mOldFileMapping\n            if (line.contains(\"/\")) {\n              mOldFileMapping.put(nameBefore, nameAfter);\n            } else {\n              //这里是resid的mapping\n              int packagePos = nameBefore.indexOf(\".R.\");\n              if (packagePos == -1) {\n                throw new IOException(String.format(\"the old mapping file packagename is malformed, \"\n                                                    + \"it should be like com.tencent.mm.R.attr.test, yours %s\\n\",\n                    nameBefore\n                ));\n              }\n              String packageName = nameBefore.substring(0, packagePos);\n              int nextDot = nameBefore.indexOf(\".\", packagePos + 3);\n              String typeName = nameBefore.substring(packagePos + 3, nextDot);\n\n              String beforename = nameBefore.substring(nextDot + 1);\n              String aftername = nameAfter.substring(nameAfter.indexOf(\".\", packagePos + 3) + 1);\n\n              HashMap<String, HashMap<String, String>> typeMap;\n\n              if (mOldResMapping.containsKey(packageName)) {\n                typeMap = mOldResMapping.get(packageName);\n              } else {\n                typeMap = new HashMap<>();\n              }","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/shwenzhang/AndResGuard/blob/e4df245d82f27d9a2d0dd108260a3510cbaba849/AndResGuard-core/src/main/java/com/tencent/mm/resourceproguard/Configuration.java#L473-L509","documentation":"While parsing the old proguard mapping.txt in keep-mapping mode, each 'from -> to' line without a '/' is treated as a resource-id mapping whose 'from' name must contain the marker \".R.\" (e.g. com.tencent.mm.R.attr.test). If nameBefore lacks \".R.\", the parser cannot extract the package name and throws this IOException. It indicates the mapping file is not the expected proguard resource mapping format.","triggerScenarios":"A line in the old mapping.txt whose left-hand side (nameBefore) matches the MAP_PATTERN (\\s+(.*)->(.*)) but contains neither a '/' (file mapping) nor a \".R.\" segment (resource mapping) — e.g. class-name-only entries or a mapping.txt from a proguard configuration that does not emit resource names in the expected form.","commonSituations":"Feeding AndResGuard a plain code mapping.txt (classes only) instead of one containing resource mappings; mapping produced by R8 with different formatting than proguard; editing mapping.txt by hand and corrupting resource entries.","solutions":["Use the mapping.txt actually produced alongside the previous obfuscated build (one that contains res name entries like com.pkg.R.drawable.name), not a classes-only mapping","Verify each mapping line's left side contains .R. for resource entries, or a '/' for file entries; fix or remove malformed lines","If R8 output format is incompatible, regenerate the mapping with proguard or with the AndResGuard version matching your build chain"],"exampleFix":"// before (mapping.txt entry)\ncom.pkg.SomeClass -> com.pkg.a:\n// after (mapping.txt entry)\ncom.pkg.R.drawable.icon -> com.pkg.a.a","handlingStrategy":"validation","validationCode":"java.io.BufferedReader r = new java.io.BufferedReader(new java.io.FileReader(mappingFile));\nString line;\nwhile ((line = r.readLine()) != null) {\n  java.util.Matcher m = java.util.regex.Pattern.compile(\"\\\\s+(.*)->(.*)\").matcher(line);\n  if (m.find() && !m.group(1).contains(\"/\") && !m.group(1).contains(\".R.\")) {\n    throw new IllegalStateException(\"mapping line lacks .R. marker: \" + line);\n  }\n}\nr.close();","typeGuard":null,"tryCatchPattern":"try {\n  new Configuration(configFile, ...);\n} catch (IOException e) {\n  if (e.getMessage().contains(\"packagename is malformed\")) {\n    // replace the old mapping.txt with one from a matching obfuscated build\n  }\n  throw e;\n}","preventionTips":["Only feed AndResGuard mapping files that contain resource-name entries (com.pkg.R.type.name) from the previous release","Do not hand-edit mapping.txt; regenerate it from the matching build","Keep the mapping.txt of each release archived alongside its APK for future keep-mapping runs"],"tags":["android","mapping","proguard","format"],"backgroundTag":"invalid-identifier-format","analyzedSha":"e4df245d82f27d9a2d0dd108260a3510cbaba849","analyzedAt":"2026-09-12T17:49:07.798Z","contentChangedAt":"2026-09-12T17:49:07.798Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}