MuntashirAkon/AppManager · error · BackupException

Failed to extract the apk file(s).

Error message

Failed to extract the apk file(s).

What it means

Once decrypted, restoreApkFiles extracts the APK files from the backup tar archive(s) into the package staging directory using TarUtils.extract. This error means extraction threw any Throwable (corrupt archive, unsupported compression, I/O failure). The broad catch ensures any tar-related failure aborts the restore with a clear message.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/backup/RestoreOp.java:361

                allApkNames[0] = mBackupMetadata.apkName;
                for (int i = 1; i < allApkNames.length; ++i) {
                    allApkNames[i] = mBackupMetadata.splitConfigs[i - 1];
                    allApks[i] = packageStagingDirectory.createNewFile(allApkNames[i], null);
                }
            } catch (IOException e) {
                throw new BackupException("Could not create staging files", e);
            }
            // Decrypt sources
            try {
                backupSourceFiles = mBackupItem.decrypt(backupSourceFiles);
            } catch (IOException e) {
                throw new BackupException("Failed to decrypt " + Arrays.toString(backupSourceFiles), e);
            }
            // Extract apk files to the package staging directory
            try {
                TarUtils.extract(mBackupInfo.tarType, backupSourceFiles, packageStagingDirectory, allApkNames, null, null);
            } catch (Throwable th) {
                throw new BackupException("Failed to extract the apk file(s).", th);
            }
            // A normal update will do it now
            InstallerOptions options = InstallerOptions.getDefault();
            options.setInstallerName(mBackupMetadata.installer);
            options.setUserId(mUserId);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
                options.setInstallScenario(PackageManager.INSTALL_SCENARIO_BULK);
            }
            AtomicReference<String> status = new AtomicReference<>();
            PackageInstallerCompat packageInstaller = PackageInstallerCompat.getNewInstance();
            packageInstaller.setOnInstallListener(new PackageInstallerCompat.OnInstallListener() {
                @Override
                public void onStartInstall(int sessionId, String packageName) {
                }

                @Override
                public void onFinishedInstall(int sessionId, String packageName, int result, @Nullable String blockingPackage, @Nullable String statusMessage) {
                    status.set(statusMessage);

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Verify mBackupInfo.tarType matches the actual archive format (zstd/gzip/plain).
  2. Re-create or re-transfer the backup — a truncated tar is the most common cause.
  3. Free storage and retry the restore.
  4. Skip no-longer-supported compression by re-packing the backup with a supported format.
Defensive patterns

Strategy: try-catch

Validate before calling

if (!mBackupInfo.tarType.canExtract(backupSourceFiles)) throw new IllegalStateException("Unsupported tar type: " + mBackupInfo.tarType);

Try / catch

try { TarUtils.extract(tarType, sources, dest, names, null, null); } catch (Throwable th) { throw new BackupException("Failed to extract the apk file(s).", th); } // log th fully to distinguish corruption vs I/O

Prevention

When it happens

Trigger: TarUtils.extract(mBackupInfo.tarType, backupSourceFiles, packageStagingDirectory, allApkNames, ...) fails: wrong tarType, corrupted/truncated tar member, unsupported compression, or write failure into the staging dir.

Common situations: Backups moved between devices and partially copied; tarType metadata mismatches the actual archive format; extraction to /data/local/tmp-like staging fails due to space or SELinux restrictions.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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