MuntashirAkon/AppManager · error · BackupException

Package name mismatch: Expected=${mPackageName}, Actual=${mP

Error message

Package name mismatch: Expected=${mPackageName}, Actual=${mPackageInfo.packageName}

What it means

Thrown by SBConverter.generateMetadata when the package name parsed from the cached APK does not match mPackageName (the expected name derived from the backup/metadata). It's a consistency guard preventing converted backups whose contents don't match their declared identity.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/backup/convert/SBConverter.java:294

                IoUtils.copy(pis, fos);
            }
            mFilesToBeDeleted.add(getApkFile());
        } catch (IOException e) {
            throw new BackupException("Could not cache APK file", e);
        }
        String filePath = Objects.requireNonNull(mCachedApk.getFilePath());
        PackageInfo packageInfo = mPm.getPackageArchiveInfo(filePath, 0);
        if (packageInfo == null) {
            throw new BackupException("Could not fetch package info");
        }
        mPackageInfo = packageInfo;
        Objects.requireNonNull(mPackageInfo.applicationInfo);
        mPackageInfo.applicationInfo.publicSourceDir = filePath;
        mPackageInfo.applicationInfo.sourceDir = filePath;
        ApplicationInfo applicationInfo = mPackageInfo.applicationInfo;

        if (!mPackageInfo.packageName.equals(mPackageName)) {
            throw new BackupException("Package name mismatch: Expected=" + mPackageName + ", Actual=" + mPackageInfo.packageName);
        }

        metadataV2.label = applicationInfo.loadLabel(mPm).toString();
        metadataV2.packageName = mPackageName;
        metadataV2.versionName = mPackageInfo.versionName;
        metadataV2.versionCode = PackageInfoCompat.getLongVersionCode(mPackageInfo);
        metadataV2.isSystem = false;
        metadataV2.hasRules = false;
        metadataV2.backupTime = mBackupTime;
        metadataV2.crypto = CryptoUtils.MODE_NO_ENCRYPTION;
        metadataV2.apkName = "base.apk";
        // Backup flags
        BackupFlags flags = new BackupFlags(BackupFlags.BACKUP_APK_FILES);
        try {
            mFilesToBeDeleted.add(getObbFile());
            flags.addFlag(BackupFlags.BACKUP_EXT_OBB_MEDIA);
        } catch (FileNotFoundException ignore) {
        }

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Dump the APK's real package name (aapt dump badging base.apk | grep package) and align the folder/metadata with it.
  2. Fix metadata.apkName so it references the correct base APK for the declared package.
  3. If the wrong app was placed in the folder, restore the correct APK from the original backup.
  4. Do not hand-edit packageName in metadata; let generateMetadata derive identity from the APK.

Example fix

// before: metadata edited by hand
metadata.packageName = "com.example.renamed";
// after: keep the real package name from the APK
String real = getPackageNameFromApk(baseApk); // aapt/PackageManager
metadata.packageName = real; // folder name must equal real too
Defensive patterns

Strategy: validation

Validate before calling

PackageInfo pi = pm.getPackageArchiveInfo(apkPath, 0);
if (pi != null && !pi.packageName.equals(expectedPackageName))
    throw new IllegalStateException("folder/app mismatch: expected "
        + expectedPackageName + " but APK is " + pi.packageName);

Try / catch

try { converter.convert(); }
catch (BackupException e) {
    if (e.getMessage().startsWith("Package name mismatch")) {
        // derive the real package from the message and rename the folder/metadata
    }
}

Prevention

When it happens

Trigger: metadata.apkName points to the wrong APK (a different app) inside the source folder; the backup folder was renamed/reassigned to another package; hand-edited metadata declares a package name that differs from the actual APK manifest.

Common situations: Users renaming or merging backup folders manually; cloning a backup folder as a template for another app; source archives containing multiple APKs where name resolution picked the wrong one.

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


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