{"record":{"id":"4f5d57506af260b9","repo":"LSPosed/LSPosed","slug":"could-not-determine-package-name-for-resdir","errorCode":null,"errorMessage":"Could not determine package name for ${resDir}","messagePattern":"Could not determine package name for (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/android/content/res/XResources.java","lineNumber":183,"sourceCode":"\t}\n\n\tprivate static String getPackageName(String resDir) {\n\t\tif (resDir == null)\n\t\t\treturn \"android\";\n\n\t\tString packageName;\n\t\tsynchronized (sResDirPackageNames) {\n\t\t\tpackageName = sResDirPackageNames.get(resDir);\n\t\t}\n\n\t\tif (packageName != null)\n\t\t\treturn packageName;\n\n\t\tPackageParser.PackageLite pkgInfo;\n\t\ttry {\n\t\t\tpkgInfo = PackageParser.parsePackageLite(new File(resDir), 0);\n\t\t} catch (PackageParserException e) {\n\t\t\tthrow new IllegalStateException(\"Could not determine package name for \" + resDir, e);\n\t\t}\n\t\tif (pkgInfo != null && pkgInfo.packageName != null) {\n//\t\t\tLog.w(XposedBridge.TAG, \"Package name for \" + resDir + \" had to be retrieved via parser\");\n\t\t\tpackageName = pkgInfo.packageName;\n\t\t\tsetPackageNameForResDir(packageName, resDir);\n\t\t\treturn packageName;\n\t\t}\n\n\t\tthrow new IllegalStateException(\"Could not determine package name for \" + resDir);\n\t}\n\n\t/**\n\t * Special case of {@link #getPackageName} during object creation.\n\t *\n\t * <p>For a short moment during/after the creation of a new {@link android.content.res Resources}\n\t * object, it isn't an instance of {@link XResources} yet. For any hooks that need information\n\t * about the just created object during this particular stage, this method will return the\n\t * package name.","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/LSPosed/LSPosed/blob/df74d83eb03a44cc6ad268841ac2ada28d077c77/core/src/main/java/android/content/res/XResources.java#L165-L201","documentation":"XResources.getPackageName(String resDir) throws IllegalStateException('Could not determine package name for <resDir>') when the resource directory path is not in the sResDirPackageNames cache and PackageParser.parsePackageLite fails on it (this variant wraps the PackageParserException as cause). It means the given path is not a parseable APK — missing, not an APK, or unreadable — so the package name cannot be recovered for resource hook dispatch.","triggerScenarios":"Passing a resDir that does not exist on disk, points to a directory that is not an APK (e.g. an extracted resources.arsc, a split config dir, an ODEX/VDEX file), or an APK the platform parser rejects (corrupt zip, truncated download, protobuf-parsed APEX).","commonSituations":"Hooking resources of an app whose APK was updated/moved between lookup and parse (dynamic updates, adb reinstall mid-session), hardcoding an APK path that differs across OEM builds, or resource hooks firing for isolated/special processes where the app dir is inaccessible.","solutions":["Verify the resDir exists and is a valid APK (PackageManager.getApplicationInfo(pkg, 0).sourceDir) before relying on getPackageName.","Pre-register the mapping with XResources.setPackageNameForResDir(packageName, resDir) if you already know the package — this bypasses parsing entirely.","If the APK moved, re-fetch sourceDir from PackageManager instead of caching it.","Inspect the caused-by PackageParserException to see the exact parse failure."],"exampleFix":"// before\nString pkg = XResources.getPackageName(resDir); // throws if APK unreadable\n// after\nXResources.setPackageNameForResDir(expectedPkg, resDir); // known mapping, no parse\nString pkg = XResources.getPackageName(resDir);","handlingStrategy":"validation","validationCode":"File apk = new File(resDir);\nif (apk.isFile()) {\n    XResources.setPackageNameForResDir(pm.getApplicationInfo(pkg,0).packageName, resDir);\n    String name = XResources.getPackageName(resDir);\n}","typeGuard":null,"tryCatchPattern":"catch (IllegalStateException e) { log and skip resource hooking for this resDir; e.getCause() carries the PackageParserException }","preventionTips":["Pre-register package-name mappings with setPackageNameForResDir when the owner is known.","Always resolve resDir from PackageManager.sourceDir, never hardcode paths."],"tags":["xposed","resources","package-parser","invalid-path","apk"],"backgroundTag":null,"analyzedSha":"df74d83eb03a44cc6ad268841ac2ada28d077c77","analyzedAt":"2026-08-14T10:46:48.326Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}