MuntashirAkon/AppManager · error · PackageManager.NameNotFoundException
Package cannot be parsed.
Error message
Package cannot be parsed.
What it means
PackageInstallerViewModel.loadNewPackageInfo throws PackageManager.NameNotFoundException("Package cannot be parsed.") when PackageManager.getPackageArchiveInfo() returns null for the given APK path, both with and without the GET_SIGNING_CERTIFICATES flag. It means the framework's PackageParser could not extract a PackageInfo from the file, so the APK is not a readable/valid Android package. The installer cannot proceed without package metadata.
Source
Thrown at app/src/main/java/io/github/muntashirakon/AppManager/apk/installer/PackageInstallerViewModel.java:366
mSelectedSplits.clear();
mPackageParseResultLiveData.setValue(null);
}
@WorkerThread
@NonNull
private PackageInfo loadNewPackageInfo(@NonNull ApkFile apkFile) throws PackageManager.NameNotFoundException, IOException {
String apkPath = apkFile.getBaseEntry().getFile(false).getAbsolutePath();
int flags = PackageManager.GET_PERMISSIONS
| PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS | PackageManager.GET_PROVIDERS
| PackageManager.GET_SERVICES | MATCH_DISABLED_COMPONENTS | GET_SIGNING_CERTIFICATES_APK
| PackageManager.GET_CONFIGURATIONS | PackageManager.GET_SHARED_LIBRARY_FILES;
PackageInfo packageInfo = mPm.getPackageArchiveInfo(apkPath, flags);
if (packageInfo == null) {
// Previous method could return null if the APK isn't signed. So, try without it.
packageInfo = mPm.getPackageArchiveInfo(apkPath, flags & ~GET_SIGNING_CERTIFICATES_APK);
}
if (packageInfo == null) {
throw new PackageManager.NameNotFoundException("Package cannot be parsed.");
}
packageInfo.applicationInfo.sourceDir = apkPath;
packageInfo.applicationInfo.publicSourceDir = apkPath;
return packageInfo;
}
public static final class PackageParseResult {
@NonNull
private final String operationId;
@NonNull
private final PackageInfo newPackageInfo;
@Nullable
private final PackageInfo installedPackageInfo;
@NonNull
private final ApkSource apkSource;
@NonNull
private final ApkFile apkFile;
@NonNullView on GitHub (pinned to 0152f468fc)
Solutions
- Verify the file exists and is a complete APK: check File length > 0 and that the first bytes are the ZIP magic 'PK'.
- Re-download or re-obtain the APK; compare its checksum against the source to rule out corruption.
- Test parsing outside the app with aapt dump badging <apk> to see what the parser dislikes.
- If using split/merged APKs, rebuild the merge so the base APK contains a valid binary AndroidManifest.xml.
- Check storage permissions / Storage Access Framework URI resolution so the path is actually readable before calling getPackageArchiveInfo.
Example fix
// before
PackageInfo pi = mPm.getPackageArchiveInfo(apkPath, flags);
if (pi == null) throw new PackageManager.NameNotFoundException("Package cannot be parsed.");
// after
File apkFile = new File(apkPath);
if (!apkFile.isFile() || apkFile.length() < 4) {
throw new IOException("APK missing or truncated: " + apkPath);
}
PackageInfo pi = mPm.getPackageArchiveInfo(apkPath, flags);
if (pi == null) {
throw new PackageManager.NameNotFoundException("Package cannot be parsed: " + apkPath);
} Defensive patterns
Strategy: try-catch
Validate before calling
File f = new File(apkPath);
if (!f.isFile() || f.length() < 4) return false;
try (RandomAccessFile raf = new RandomAccessFile(f, "r")) {
return raf.read() == 'P' && raf.read() == 'K';
} Type guard
static boolean isPlausibleApk(String apkPath) {
File f = new File(apkPath);
return f.isFile() && f.length() >= 22; // minimal ZIP header + EOCD
} Try / catch
try {
PackageInfo pi = viewModel.newPackageInfo(apkPath);
} catch (PackageManager.NameNotFoundException e) {
Toast.makeText(ctx, "APK is corrupt or not an Android package", Toast.LENGTH_LONG).show();
Log.e(TAG, "getPackageArchiveInfo returned null for " + apkPath, e);
} Prevention
- Verify file size and ZIP magic before handing the path to the installer.
- Re-download APKs over resumable/verified transfers and compare checksums.
- Never rename arbitrary files to .apk and feed them to the installer.
- Log the APK path and size whenever parsing fails to speed up diagnosis.
When it happens
Trigger: Calling the installer flow (newPackageInfo -> loadNewPackageInfo) with an apkPath whose file is not a parseable APK: corrupted/partial download, non-APK file with .apk extension, path on inaccessible storage, or a malformed resource/manifest table the platform parser rejects.
Common situations: Sideloading an interrupted download, testing a placeholder/renamed file, split APKs assembled incorrectly, APKs built with features the current OS version cannot parse, or files under app-private storage not yet readable by the parsing process.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Package not found.
- "manifest" tag not found.
- Could not fetch package info
- Package cannot be parsed
- "manifest" has duplicate "application" tags.
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/f409a665f497d2d5.
Report an issue: GitHub.