{"record":{"id":"9596896e9511f9b0","repo":"MuntashirAkon/AppManager","slug":"package-not-found","errorCode":null,"errorMessage":"Package not found.","messagePattern":"Package not found\\.","errorType":"exception","errorClass":"PackageManager.NameNotFoundException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/apk/installer/PackageInstallerViewModel.java","lineNumber":484,"sourceCode":"\n    private synchronized void persistInstallResult() {\n        if (mInstallResult != null) {\n            mSavedStateHandle.set(STATE_INSTALL_RESULT, mInstallResult);\n        } else {\n            mSavedStateHandle.remove(STATE_INSTALL_RESULT);\n        }\n    }\n\n    @WorkerThread\n    @NonNull\n    private PackageInfo loadInstalledPackageInfo(String packageName) throws PackageManager.NameNotFoundException {\n        @SuppressLint(\"WrongConstant\")\n        PackageInfo packageInfo = mPm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS\n                | PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS | PackageManager.GET_PROVIDERS\n                | PackageManager.GET_SERVICES | MATCH_DISABLED_COMPONENTS | GET_SIGNING_CERTIFICATES | MATCH_UNINSTALLED_PACKAGES\n                | PackageManager.GET_CONFIGURATIONS | PackageManager.GET_SHARED_LIBRARY_FILES);\n        if (packageInfo == null) {\n            throw new PackageManager.NameNotFoundException(\"Package not found.\");\n        }\n        return packageInfo;\n    }\n}\n","sourceCodeStart":466,"sourceCodeEnd":489,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/apk/installer/PackageInstallerViewModel.java#L466-L489","documentation":"loadInstalledPackageInfo throws PackageManager.NameNotFoundException(\"Package not found.\") when getPackageInfo() returns null for the given package name despite querying with MATCH_UNINSTALLED_PACKAGES and MATCH_DISABLED_COMPONENTS. This means no installed (or recently uninstalled-but-still-cached) package matches the name on this user/profile. It is thrown when building PackageInstaller metadata for an already-installed target app.","triggerScenarios":"loadPackageInfo -> loadInstalledPackageInfo is called with a packageName that is not installed: wrong applicationId, app uninstalled, querying a different user/profile, package only present in another work profile, or app removed between the listing and this call.","commonSituations":"Stale package name after an app was renamed/uninstalled, querying without the right user handle (UserManager profiles), app rejected or uninstalled after installer launched, or applicationId suffix (e.g. .debug) differing from the expected name.","solutions":["Confirm the exact applicationId via `adb shell pm list packages | grep <name>` on the same device/user.","Resolve the correct UserHandle and call getPackageInfoAsUser instead of the default-user variant.","Re-check installation status immediately before the call and handle uninstalled packages gracefully.","Account for build-type suffixes (debug/release applicationIdSuffix) when constructing the package name.","Catch NameNotFoundException and surface a clear 'app not installed' message instead of crashing."],"exampleFix":"// before\nPackageInfo pi = mPm.getPackageInfo(packageName, flags);\nif (pi == null) throw new PackageManager.NameNotFoundException(\"Package not found.\");\n// after\nPackageInfo pi;\ntry {\n    pi = mPm.getPackageInfo(packageName, flags);\n} catch (PackageManager.NameNotFoundException e) {\n    throw new PackageManager.NameNotFoundException(\n        \"Package not found for current user: \" + packageName);\n}\nif (pi == null) throw new PackageManager.NameNotFoundException(\"Package not found: \" + packageName);","handlingStrategy":"try-catch","validationCode":"boolean installed = getPackageManager().getInstalledPackages(0).stream()\n    .anyMatch(p -> p.packageName.equals(packageName));","typeGuard":null,"tryCatchPattern":"try {\n    PackageInfo pi = mPm.getPackageInfo(packageName, flags);\n} catch (PackageManager.NameNotFoundException e) {\n    showUserVisibleError(\"Target app \" + packageName + \" is not installed on this user profile\");\n}","preventionTips":["Always resolve package names via PackageManager at call time, never cache them.","Handle multi-user/work-profile cases by resolving the right UserHandle.","Double-check applicationIdSuffix for debug builds.","Treat NameNotFoundException as an expected condition in installer flows, not a crash."],"tags":["android","package-manager","installer","not-found"],"backgroundTag":"entity-not-found","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"}