LSPosed/LSPosed · error · IllegalStateException
Could not determine package name for ${resDir}
Error message
Could not determine package name for ${resDir} What it means
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.
Source
Thrown at core/src/main/java/android/content/res/XResources.java:183
}
private static String getPackageName(String resDir) {
if (resDir == null)
return "android";
String packageName;
synchronized (sResDirPackageNames) {
packageName = sResDirPackageNames.get(resDir);
}
if (packageName != null)
return packageName;
PackageParser.PackageLite pkgInfo;
try {
pkgInfo = PackageParser.parsePackageLite(new File(resDir), 0);
} catch (PackageParserException e) {
throw new IllegalStateException("Could not determine package name for " + resDir, e);
}
if (pkgInfo != null && pkgInfo.packageName != null) {
// Log.w(XposedBridge.TAG, "Package name for " + resDir + " had to be retrieved via parser");
packageName = pkgInfo.packageName;
setPackageNameForResDir(packageName, resDir);
return packageName;
}
throw new IllegalStateException("Could not determine package name for " + resDir);
}
/**
* Special case of {@link #getPackageName} during object creation.
*
* <p>For a short moment during/after the creation of a new {@link android.content.res Resources}
* object, it isn't an instance of {@link XResources} yet. For any hooks that need information
* about the just created object during this particular stage, this method will return the
* package name.View on GitHub (pinned to df74d83eb0)
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.
Example fix
// before String pkg = XResources.getPackageName(resDir); // throws if APK unreadable // after XResources.setPackageNameForResDir(expectedPkg, resDir); // known mapping, no parse String pkg = XResources.getPackageName(resDir);
Defensive patterns
Strategy: validation
Validate before calling
File apk = new File(resDir);
if (apk.isFile()) {
XResources.setPackageNameForResDir(pm.getApplicationInfo(pkg,0).packageName, resDir);
String name = XResources.getPackageName(resDir);
} Try / catch
catch (IllegalStateException e) { log and skip resource hooking for this resDir; e.getCause() carries the PackageParserException } Prevention
- Pre-register package-name mappings with setPackageNameForResDir when the owner is known.
- Always resolve resDir from PackageManager.sourceDir, never hardcode paths.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- path must not be null
- This method can only be called during getTopLevelResources()
- ${pkg}:${type}/${name}
- Failed to initialize resources hook
- id 0 is not an allowed resource identifier
AI-assisted analysis of LSPosed/LSPosed@df74d83eb0 (2026-08-14).
Data as JSON: /api/errors/4f5d57506af260b9.
Report an issue: GitHub.