MuntashirAkon/AppManager · error · PackageManager.NameNotFoundException

Package not found.

Error message

Package not found.

What it means

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.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/apk/installer/PackageInstallerViewModel.java:484

    private synchronized void persistInstallResult() {
        if (mInstallResult != null) {
            mSavedStateHandle.set(STATE_INSTALL_RESULT, mInstallResult);
        } else {
            mSavedStateHandle.remove(STATE_INSTALL_RESULT);
        }
    }

    @WorkerThread
    @NonNull
    private PackageInfo loadInstalledPackageInfo(String packageName) throws PackageManager.NameNotFoundException {
        @SuppressLint("WrongConstant")
        PackageInfo packageInfo = mPm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS
                | PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS | PackageManager.GET_PROVIDERS
                | PackageManager.GET_SERVICES | MATCH_DISABLED_COMPONENTS | GET_SIGNING_CERTIFICATES | MATCH_UNINSTALLED_PACKAGES
                | PackageManager.GET_CONFIGURATIONS | PackageManager.GET_SHARED_LIBRARY_FILES);
        if (packageInfo == null) {
            throw new PackageManager.NameNotFoundException("Package not found.");
        }
        return packageInfo;
    }
}

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Confirm the exact applicationId via `adb shell pm list packages | grep <name>` on the same device/user.
  2. Resolve the correct UserHandle and call getPackageInfoAsUser instead of the default-user variant.
  3. Re-check installation status immediately before the call and handle uninstalled packages gracefully.
  4. Account for build-type suffixes (debug/release applicationIdSuffix) when constructing the package name.
  5. Catch NameNotFoundException and surface a clear 'app not installed' message instead of crashing.

Example fix

// before
PackageInfo pi = mPm.getPackageInfo(packageName, flags);
if (pi == null) throw new PackageManager.NameNotFoundException("Package not found.");
// after
PackageInfo pi;
try {
    pi = mPm.getPackageInfo(packageName, flags);
} catch (PackageManager.NameNotFoundException e) {
    throw new PackageManager.NameNotFoundException(
        "Package not found for current user: " + packageName);
}
if (pi == null) throw new PackageManager.NameNotFoundException("Package not found: " + packageName);
Defensive patterns

Strategy: try-catch

Validate before calling

boolean installed = getPackageManager().getInstalledPackages(0).stream()
    .anyMatch(p -> p.packageName.equals(packageName));

Try / catch

try {
    PackageInfo pi = mPm.getPackageInfo(packageName, flags);
} catch (PackageManager.NameNotFoundException e) {
    showUserVisibleError("Target app " + packageName + " is not installed on this user profile");
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/9596896e9511f9b0. Report an issue: GitHub.