MuntashirAkon/AppManager · error · BackupException
Failed to setup metadata.
Error message
Failed to setup metadata.
What it means
BackupOp's constructor calls setupMetadataAndCrypto() to build the backup metadata (package info, crypto setup); any Throwable there triggers cleanup of the backup item and BackupException('Failed to setup metadata.', e). This means backup initialization failed before any data was written — commonly a crypto/key problem or missing package info.
Source
Thrown at app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupOp.java:129
BackupOp(@NonNull String packageName, @NonNull BackupFlags backupFlags,
@NonNull BackupItems.BackupItem backupItem, @UserIdInt int userId)
throws BackupException {
mPackageName = packageName;
mBackupItem = backupItem;
mUserId = userId;
mBackupFlags = backupFlags;
mPm = ContextUtils.getContext().getPackageManager();
try {
mPackageInfo = PackageManagerCompat.getPackageInfo(mPackageName,
PackageManager.GET_META_DATA | GET_SIGNING_CERTIFICATES | PackageManager.GET_PERMISSIONS
| PackageManagerCompat.MATCH_STATIC_SHARED_AND_SDK_LIBRARIES, userId);
Objects.requireNonNull(mPackageInfo);
mApplicationInfo = Objects.requireNonNull(mPackageInfo.applicationInfo);
// Override existing metadata
mMetadata = setupMetadataAndCrypto();
} catch (Throwable e) {
mBackupItem.cleanup();
throw new BackupException("Failed to setup metadata.", e);
}
try {
mChecksum = mBackupItem.getChecksum();
String[] certChecksums = PackageUtils.getSigningCertChecksums(mMetadata.info.checksumAlgo, mPackageInfo, false);
for (int i = 0; i < certChecksums.length; ++i) {
mChecksum.add(CERT_PREFIX + i, certChecksums[i]);
}
} catch (Throwable e) {
mBackupItem.cleanup();
throw new BackupException("Failed to create checksum file.", e);
}
}
@Override
public void close() {
mBackupItem.cleanup();
}
View on GitHub (pinned to 0152f468fc)
Solutions
- Read getCause() to find the real failure (crypto vs package info).
- Re-set up backup encryption keys/passwords in the app settings; retry after the keystore is unlocked.
- Confirm the target package is still installed for the given userId before starting the backup.
- If crypto is the issue, temporarily back up without encryption to isolate the problem; catch BackupException and clean up partial state (the constructor already calls mBackupItem.cleanup()).
Example fix
// before
new BackupOp(context, new BackupOpOptions(pkg, userId, flags, crypto)); // throws
// after
try {
new BackupOp(context, options);
} catch (BackupException e) {
Log.e(TAG, "metadata setup failed", e.getCause());
if (e.getCause() instanceof CryptoException) {
// prompt user to reconfigure backup encryption
}
} Defensive patterns
Strategy: try-catch
Validate before calling
PackageInfo pi = pm.getPackageInfoAsUser(pkg, 0, userId);
if (pi == null || pi.applicationInfo == null) {
throw new IllegalStateException("Package not installed: " + pkg + " user " + userId);
} Type guard
boolean backupTargetReady(Context ctx, String pkg, int userId) {
PackageInfo pi = PackageUtils.getPackageInfoAsUser(pkg, 0, userId);
return pi != null && pi.applicationInfo != null;
} Try / catch
try {
new BackupOp(context, options);
} catch (BackupException e) {
Throwable cause = e.getCause();
if ("Failed to setup metadata.".equals(e.getMessage()) && cause != null) {
Log.e(TAG, "backup init failed", cause); // crypto vs package-info branch
}
} Prevention
- Verify package installation state immediately before backup
- Set up/validate backup encryption keys before starting backups
- Unlock the device keystore prior to encrypted backups
- Always catch BackupException around BackupOp construction since the constructor performs setup work
When it happens
Trigger: Running a backup where metadata/crypto setup fails: keystore key unavailable or invalidated, bad crypto algorithm/args, PackageInfo/ApplicationInfo unresolvable for the target package, or any exception inside setupMetadataAndCrypto().
Common situations: Device keystore locked or keys cleared after OS update/factory reset; encrypted backups requested without proper key/password setup; backing up a package that was uninstalled between listing and backup; checksum-algo misconfiguration.
Related errors
- Failed to get crypto
- Could not retrieve metadata from backup.
- The app has keystore items and KeyStore backup isn't enabled
- Failed to write metadata.
- Failed to get crypto
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/57515c946911e304.
Report an issue: GitHub.