shwenzhang/AndResGuard · error · MinSdkVersionException

Failed to determine APK's minimum supported platform…

Error message

Failed to determine APK's minimum supported platform version. Use --min-sdk-version to override

What it means

The signing engine must know the APK's minimum supported platform version (read from the manifest); when it cannot determine it, sign() throws MinSdkVersionException which the tool re-wraps with guidance to pass --min-sdk-version explicitly.

Solutions

  1. Pass --min-sdk-version <n> explicitly (match your build.gradle minSdkVersion)
  2. Rebuild or repair the APK so its manifest is parseable
  3. Verify the input is a valid APK (unzip and inspect AndroidManifest.xml)

Example fix

// before
apksigner sign --ks ks.jks app.apk
// after
apksigner sign --ks ks.jks --min-sdk-version 21 app.apk
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check the APK's manifest is parseable, or just always pass the flag:
List<String> cmd = new ArrayList<>(List.of("apksigner","sign","--min-sdk-version", String.valueOf(minSdkFromBuildConfig)));

Try / catch

try { apkSigner.sign(); }
catch (MinSdkVersionException e) {
    System.err.println("Set --min-sdk-version explicitly (e.g. your build.gradle minSdkVersion)");
    // retry with explicit minSdkVersion
}

Prevention

When it happens

Trigger: APK whose AndroidManifest cannot be parsed for minSdkVersion (unusual or corrupted manifest, missing uses-sdk attrs the parser expects) and no --min-sdk-version flag given.

Common situations: Heavily processed APKs (e.g. after obfuscation/resource shrinking) with malformed binary manifest; APKs built by non-standard tools; missing explicit minSdk in the manifest.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


AI-assisted analysis of shwenzhang/AndResGuard@e4df245d82 (2026-09-12). Data as JSON: /api/errors/61b189da59fece36. Report an issue: GitHub.

Appendix: source

Thrown at AndResGuard-core/src/main/java/apksigner/ApkSignerTool.java:283

    }
    ApkSigner.Builder apkSignerBuilder = new ApkSigner.Builder(signerConfigs).setInputApk(inputApk)
        .setOutputApk(tmpOutputApk)
        .setOtherSignersSignaturesPreserved(false)
        .setV1SigningEnabled(v1SigningEnabled)
        .setV2SigningEnabled(v2SigningEnabled)
        .setV3SigningEnabled(v3SigningEnabled);
    if (minSdkVersionSpecified) {
      apkSignerBuilder.setMinSdkVersion(minSdkVersion);
    }
    ApkSigner apkSigner = apkSignerBuilder.build();
    try {
      apkSigner.sign();
    } catch (MinSdkVersionException e) {
      String msg = e.getMessage();
      if (!msg.endsWith(".")) {
        msg += '.';
      }
      throw new MinSdkVersionException("Failed to determine APK's minimum supported platform version"
                                       + ". Use --min-sdk-version to override", e);
    }
    if (!tmpOutputApk.getCanonicalPath().equals(outputApk.getCanonicalPath())) {
      Files.move(tmpOutputApk.toPath(), outputApk.toPath(), StandardCopyOption.REPLACE_EXISTING);
    }

    if (verbose) {
      System.out.println("Signed");
    }
  }

  private static void verify(String[] params) throws Exception {
    if (params.length == 0) {
      printUsage(HELP_PAGE_VERIFY);
      return;
    }

    File inputApk = null;

View on GitHub (pinned to e4df245d82)