Tencent/matrix · error · TaskInitException

---APK-UNZIP-PATH ' ' is not directory!

Error message

---APK-UNZIP-PATH '<inputPath>' is not directory!

What it means

Thrown from UnusedResourcesTask.init() when the configured unzip path exists but is not a directory. The task requires the extracted APK's directory tree (with res/ contents) to check for unused resources; supplying a file path triggers this TaskInitException.

Solutions

  1. Point unzip path to the extracted APK directory produced by the unzip task
  2. If you only have the .apk, extract it first (unzip apk -d dir) and use dir
  3. Log/print the configured path and confirm its type

Example fix

// before
config.setUnzipPath("/build/outputs/apk/release/app-release.apk");
// after
config.setUnzipPath("/build/outputs/apk/release/apk-extracted"); // must be a directory
Defensive patterns

Strategy: validation

Validate before calling

File dir = new File(config.getUnzipPath());
if (dir.exists() && !dir.isDirectory()) throw new IllegalStateException("unzip path must be a directory");

Try / catch

try {
    task.init();
} catch (TaskInitException e) {
    log.error("unzip path is not a directory: " + e.getMessage());
}

Prevention

When it happens

Trigger: config.getUnzipPath() points to the .apk itself or some other file instead of the extraction output directory.

Common situations: Confusing the APK artifact path with the unzipped output path in Gradle plugin config or CLI -unzip argument.

Related errors


AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08). Data as JSON: /api/errors/a4e0e702f204e273. Report an issue: GitHub.

Appendix: source

Thrown at matrix/matrix-android/matrix-apk-canary/src/main/java/com/tencent/matrix/apk/model/task/UnusedResourcesTask.java:118

    public void init() throws TaskInitException {
        super.init();

        String inputPath = config.getUnzipPath();
        if (Util.isNullOrNil(inputPath)) {
            throw new TaskInitException(TAG + "---APK-UNZIP-PATH can not be null!");
        }
        if (!params.containsKey(JobConstants.PARAM_R_TXT) || Util.isNullOrNil(params.get(JobConstants.PARAM_R_TXT))) {
            throw new TaskInitException(TAG + "---The File 'R.txt' can not be null!");
        }
        resourceTxt = new File(params.get(JobConstants.PARAM_R_TXT));
        if (!FileUtil.isLegalFile(resourceTxt)) {
            throw new TaskInitException(TAG + "---The Resource declarations file 'R.txt' is not legal!");
        }
        inputFile = new File(inputPath);
        if (!inputFile.exists()) {
            throw new TaskInitException(TAG + "---APK-UNZIP-PATH '" + inputPath + "' is not exist!");
        } else if (!inputFile.isDirectory()) {
            throw new TaskInitException(TAG + "---APK-UNZIP-PATH '" + inputPath + "' is not directory!");
        }
        if (!Util.isNullOrNil(config.getMappingFilePath())) {
            mappingTxt = new File(config.getMappingFilePath());
            if (!FileUtil.isLegalFile(mappingTxt)) {
                throw new TaskInitException(TAG + "---The Proguard mapping file 'mapping.txt' is not legal!");
            }
        }
        if (params.containsKey(JobConstants.PARAM_IGNORE_RESOURCES_LIST) && !Util.isNullOrNil(params.get(JobConstants.PARAM_IGNORE_RESOURCES_LIST))) {
            String[] ignoreRes = params.get(JobConstants.PARAM_IGNORE_RESOURCES_LIST).split(",");
            for (String ignore : ignoreRes) {
                ignoreSet.add(Util.globToRegexp(ignore));
            }
        }
        if (!Util.isNullOrNil(config.getResMappingFilePath())) {
            resMappingTxt = new File(config.getResMappingFilePath());
            if (!FileUtil.isLegalFile(resMappingTxt)) {
                throw new TaskInitException(TAG + "---The Resguard mapping file 'resguard-mapping.txt' is not legal!");
            }

View on GitHub (pinned to 3b8293bd65)