MuntashirAkon/AppManager · error · PackageManager.NameNotFoundException

Package ${packageName} not found.

Error message

Package ${packageName} not found.

What it means

PackageManagerCompat.getApplicationInfo calls the hidden IPackageManager.getApplicationInfo, which may return null instead of throwing. When the returned ApplicationInfo is null, this compat method throws PackageManager.NameNotFoundException("Package <name> not found.") to signal the package does not exist for that user.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/compat/PackageManagerCompat.java:295

            info.providers = providers;
            info.receivers = receivers;
            info.permissions = permissions;
        }
        // Info should never be null here, but it's checked anyway.
        return Objects.requireNonNull(info);
    }

    @SuppressWarnings("deprecation")
    @NonNull
    public static ApplicationInfo getApplicationInfo(String packageName, int flags, @UserIdInt int userId)
            throws RemoteException, PackageManager.NameNotFoundException {
        IPackageManager pm = getPackageManager();
        ApplicationInfo applicationInfo;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            applicationInfo = pm.getApplicationInfo(packageName, (long) flags, userId);
        } else applicationInfo = pm.getApplicationInfo(packageName, flags, userId);
        if (applicationInfo == null) {
            throw new PackageManager.NameNotFoundException("Package " + packageName + " not found.");
        }
        return applicationInfo;
    }

    @Nullable
    public static String getInstallerPackageName(@NonNull String packageName, @UserIdInt int userId) {
        try {
            InstallSourceInfoCompat installSource = getInstallSourceInfo(packageName, userId);
            if (installSource.getInstallingPackageName() != null) {
                return installSource.getInstallingPackageName();
            }
            return installSource.getInitiatingPackageName();
        } catch (RemoteException | SecurityException e) {
            return null;
        }
    }

    @SuppressWarnings("deprecation")

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Wrap the call in try-catch for PackageManager.NameNotFoundException.
  2. Verify installation first via getInstalledPackages for the target user.
  3. Check packageName spelling and the userId argument.
  4. Declare the package in <queries> for visibility if targeting API 30+.

Example fix

// before
ApplicationInfo ai = PackageManagerCompat.getApplicationInfo(pkg, 0, userId);
// after
ApplicationInfo ai = null;
try {
    ai = PackageManagerCompat.getApplicationInfo(pkg, 0, userId);
} catch (PackageManager.NameNotFoundException e) {
    // handle absence
}
Defensive patterns

Strategy: try-catch

Validate before calling

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

Try / catch

try {
    ApplicationInfo ai = PackageManagerCompat.getApplicationInfo(pkg, flags, userId);
} catch (PackageManager.NameNotFoundException e) {
    ApplicationInfo ai = null;
}

Prevention

When it happens

Trigger: Calling getApplicationInfo(packageName, flags, userId) where the package is not installed for userId, or the binder call silently returns null (package hidden/removed).

Common situations: Querying apps on a different user profile; checking a package right after uninstall; missing package visibility (<queries> filtering) on Android 11+; querying system packages removed in newer OS builds.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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