{"record":{"id":"c3cea1407aba63f8","repo":"MuntashirAkon/AppManager","slug":"package-cannot-be-parsed-appdetailsviewmodel","errorCode":null,"errorMessage":"Package cannot be parsed","messagePattern":"Package cannot be parsed","errorType":"exception","errorClass":"PackageManager.NameNotFoundException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/details/AppDetailsViewModel.java","lineNumber":1134,"sourceCode":"                        mUserId);\n                if (!ApplicationInfoCompat.isInstalled(mInstalledPackageInfo.applicationInfo)) {\n                    throw new ApkFile.ApkFileException(\"App not installed. It only has data.\");\n                }\n            } catch (Throwable e) {\n                Log.e(TAG, e);\n                mInstalledPackageInfo = null;\n            }\n            if (mExternalApk) {\n                // Do not get signatures via Android framework as it will simply return NULL without any clarifications.\n                // All signatures are fetched using PackageUtils where a fallback method is used in case the PackageInfo\n                // didn't load any signature. So, we should be safe from any harm.\n                mPackageInfo = mPackageManager.getPackageArchiveInfo(mApkPath, PackageManager.GET_PERMISSIONS\n                        | PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS | PackageManager.GET_PROVIDERS\n                        | PackageManager.GET_SERVICES | MATCH_DISABLED_COMPONENTS | PackageManager.GET_CONFIGURATIONS\n                        | PackageManager.GET_SHARED_LIBRARY_FILES | PackageManager.GET_URI_PERMISSION_PATTERNS\n                        | PackageManager.GET_META_DATA);\n                if (mPackageInfo == null) {\n                    throw new PackageManager.NameNotFoundException(\"Package cannot be parsed\");\n                }\n                if (mInstalledPackageInfo == null) {\n                    Log.d(TAG, \"%s not installed for user %d\", mPackageName, mUserId);\n                }\n                mPackageInfo.applicationInfo.sourceDir = mApkPath;\n                mPackageInfo.applicationInfo.publicSourceDir = mApkPath;\n            } else {\n                mPackageInfo = mInstalledPackageInfo;\n                if (mPackageInfo == null) {\n                    throw new PackageManager.NameNotFoundException(\"Package not installed\");\n                }\n            }\n            mIsPackageExistLiveData.postValue(mIsPackageExist = true);\n        } catch (PackageManager.NameNotFoundException e) {\n            Log.e(TAG, e);\n            mIsPackageExistLiveData.postValue(mIsPackageExist = false);\n        } catch (Throwable e) {\n            Log.e(TAG, e);","sourceCodeStart":1116,"sourceCodeEnd":1152,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/details/AppDetailsViewModel.java#L1116-L1152","documentation":"For an external APK path, the ViewModel calls PackageManager.getPackageArchiveInfo(mApkPath, flags) to parse the APK's manifest. That API returns null when the archive cannot be read or its manifest is unparseable. Since the rest of the details UI needs a valid PackageInfo, the null result is converted into PackageManager.NameNotFoundException('Package cannot be parsed').","triggerScenarios":"Calling setPackage/setExternalApk with an mApkPath that is not a valid APK: corrupted download, partial file, split-APK base passed incorrectly, a .apks/.xapk bundle instead of a plain .apk, a file that no longer exists at the path, or an APK whose manifest uses features the platform parser rejects.","commonSituations":"Importing a downloaded APK that was truncated or HTML-error-page; trying to open an app bundle (.apks/.xapk/.apkm) directly; path to APK changed or file moved after being queued; platform version too old to parse a newer APK manifest.","solutions":["Verify the file is a plain .apk and is complete (re-download; check size/signature)","If it's an .apks/.xapk/.apkm bundle, extract or convert it to a single base .apk first","Confirm the path exists and is readable (SAF/permissions) before parsing","Ensure the device platform version can parse the APK; otherwise parse with a newer framework or a library like ApkParser"],"exampleFix":"// before\nFile f = new File(apkPath);\nviewModel.setExternalApk(f.getAbsolutePath()); // NameNotFoundException if f is .apks or corrupt\n// after\nFile f = new File(apkPath);\nif (f.getName().endsWith(\".apk\") && f.length() > 0 && pm.getPackageArchiveInfo(f.getAbsolutePath(), 0) != null) {\n    viewModel.setExternalApk(f.getAbsolutePath());\n} else {\n    showUnparseableApkError(apkPath);\n}","handlingStrategy":"validation","validationCode":"File apk = new File(apkPath);\nboolean parseable = apk.isFile() && apk.length() > 0 && apk.getName().endsWith(\".apk\")\n        && pm.getPackageArchiveInfo(apk.getAbsolutePath(), 0) != null;","typeGuard":"boolean isPlainApk(File f) { return f.isFile() && f.getName().endsWith(\".apk\"); }","tryCatchPattern":"try {\n    viewModel.setExternalApk(apkPath);\n} catch (PackageManager.NameNotFoundException e) {\n    showError(\"APK is corrupt, incomplete, or a bundle (.apks/.xapk) — re-download or convert\");\n}","preventionTips":["Validate downloaded APKs (size, checksum) before import","Convert .apks/.xapk/.apkm bundles to a base .apk first","Check file existence/readability before parsing","Ensure device platform supports the APK's manifest features"],"tags":["android","apk","package-manager","parsing"],"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"}