MuntashirAkon/AppManager · error · BackupException

Failed to encrypt

Error message

Failed to encrypt 

What it means

After tar creation, the freshly written APK source files are encrypted via mBackupItem.encrypt(sourceFiles). If that encryption throws IOException (stream failure, disk full, key issues), it is wrapped into this BackupException whose message includes the file list being encrypted. The unencrypted tar may have been produced but the final encrypted backup could not be completed.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/backup/convert/OABConverter.java:290

                mChecksum.add(CERT_PREFIX + i, checksums[i]);
            }
        } catch (Exception ignore) {
        }
        // Backup APK file
        String sourceBackupFilePrefix = BackupUtils.getSourceFilePrefix(getExt(mDestMetadata.info.tarType));
        Path[] sourceFiles;
        try {
            sourceFiles = TarUtils.create(mDestMetadata.info.tarType, baseApkFile, mBackupItem.getUnencryptedBackupPath(), sourceBackupFilePrefix,
                            /* language=regexp */ new String[]{".*\\.apk"}, null, null, false)
                    .toArray(new Path[0]);
        } catch (Throwable th) {
            throw new BackupException("APK files backup is requested but no APK files have been backed up.", th);
        }
        // Overwrite with the new files
        try {
            sourceFiles = mBackupItem.encrypt(sourceFiles);
        } catch (IOException e) {
            throw new BackupException("Failed to encrypt " + Arrays.toString(sourceFiles), e);
        }
        for (Path file : sourceFiles) {
            mChecksum.add(file.getName(), DigestUtils.getHexDigest(mDestMetadata.info.checksumAlgo, file));
        }
    }

    private void backupData() throws BackupException {
        List<Path> dataFiles = new ArrayList<>(2);
        if (mDestMetadata.info.flags.backupInternalData()) {
            try {
                dataFiles.add(mBackupLocation.findFile(CryptoUtils.getAppropriateFilename(mPackageName + ".zip",
                        mSourceCryptoMode)));
            } catch (FileNotFoundException e) {
                throw new BackupException("Could not get internal data backup.", e);
            }
        }
        if (mDestMetadata.info.flags.backupExternalData()) {
            try {

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Check available disk space on the backup destination and free space if needed.
  2. Verify the encryption key/crypto provider is correctly configured (or disable encryption in backup settings to produce a plaintext backup).
  3. Confirm the unencrypted backup path files still exist and are readable at encryption time.
  4. Retry the conversion; inspect the IOException cause for the underlying stream error.

Example fix

// before: encryption on but no key configured
// BackupFlags flags = new BackupFlags(BackupFlags.BACKUP_MULTIPLE | BackupFlags.BACKUP_APK_FILES);
// after: either configure crypto or drop the encryption expectation
// flags.removeFlag(BackupFlags.BACKUP_ENCRYPT); // produce unencrypted backup instead
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure encryption is configured if requested
if (flags.has(BackupFlags.BACKUP_ENCRYPT) && cryptoProvider == null) {
    throw new IllegalStateException("Encryption requested but no crypto provider configured");
}

Try / catch

try {
    converter.convert(...);
} catch (BackupException e) {
    if (e.getMessage().startsWith("Failed to encrypt")) {
        Log.e(TAG, "Encrypt step failed; check key setup and disk space", e.getCause());
    }
}

Prevention

When it happens

Trigger: backupApkFile() calls mBackupItem.encrypt(sourceFiles) and it throws IOException at OABConverter.java:290, where sourceFiles are the .apk entries just created by TarUtils.create().

Common situations: Encryption enabled in backup settings but crypto provider/key unavailable; storage full mid-encrypt; the files listed were moved/deleted between tar creation and encryption; backup item path permissions changed.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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