{"record":{"id":"87be517f41f90c15","repo":"Tencent/matrix","slug":"apk-unzip-path-inputpath-is-not-directory-87be51","errorCode":null,"errorMessage":"---APK-UNZIP-PATH '<inputPath>' is not directory!","messagePattern":"---APK-UNZIP-PATH '<inputPath>' is not directory!","errorType":"exception","errorClass":"TaskInitException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-apk-canary/src/main/java/com/tencent/matrix/apk/model/task/CountRTask.java","lineNumber":78,"sourceCode":"        dexFileList = new ArrayList<>();\n        classesMap = new HashMap<>();\n    }\n\n    @Override\n    public void init() throws TaskInitException {\n        super.init();\n        String inputPath = config.getUnzipPath();\n\n        if (Util.isNullOrNil(inputPath)) {\n            throw new TaskInitException(TAG + \"---APK-UNZIP-PATH can not be null!\");\n        }\n\n        inputFile = new File(inputPath);\n        if (!inputFile.exists()) {\n            throw new TaskInitException(TAG + \"---APK-UNZIP-PATH '\" + inputPath + \"' is not exist!\");\n        }\n        if (!inputFile.isDirectory()) {\n            throw new TaskInitException(TAG + \"---APK-UNZIP-PATH '\" + inputPath + \"' is not directory!\");\n        }\n\n        File[] files = inputFile.listFiles();\n        try {\n            if (files != null) {\n                for (File file : files) {\n                    if (file.isFile() && file.getName().endsWith(ApkConstants.DEX_FILE_SUFFIX)) {\n                        dexFileNameList.add(file.getName());\n                        RandomAccessFile randomAccessFile = new RandomAccessFile(file, \"rw\");\n                        dexFileList.add(randomAccessFile);\n                    }\n                }\n            }\n        } catch (FileNotFoundException e) {\n            throw new TaskInitException(e.getMessage(), e);\n        }\n\n    }","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-apk-canary/src/main/java/com/tencent/matrix/apk/model/task/CountRTask.java#L60-L96","documentation":"CountRTask.init() requires the unzip path to be a directory. When the path exists but is a regular file (e.g. the .apk itself rather than its extracted contents), isDirectory() fails and TaskInitException is thrown naming the path. The task iterates the directory tree to find R.class/R$*.class files.","triggerScenarios":"Configuring APK-UNZIP-PATH for CountRTask to the .apk file or any regular file instead of the directory produced by the unzip step.","commonSituations":"Mixing up the APK input and unzipped-output configuration entries; unzip step writing a single file; symlink resolved to a file; copy/paste of the APK path into the unzip-path field.","solutions":["Set APK-UNZIP-PATH to the extracted APK directory, not the .apk file.","Verify with file.isDirectory() before launching the canary job.","Separate the config keys for APK input path and unzip output path to avoid mixups.","Ensure the unzip step runs before CountRTask in the job pipeline."],"exampleFix":"// before\nconfig.setUnzipPath(inputApk.getAbsolutePath());\n// after\nFile unzipDir = new File(inputApk.getParent(), \"unzipped\");\nunzip(inputApk, unzipDir);\nconfig.setUnzipPath(unzipDir.getAbsolutePath());","handlingStrategy":"validation","validationCode":"File dir = new File(config.getUnzipPath());\nif (!dir.isDirectory()) {\n    throw new IllegalStateException(\"APK-UNZIP-PATH must be the extracted directory: \" + dir.getAbsolutePath());\n}","typeGuard":"boolean isUnzipDir(JobConfig config) {\n    String p = config.getUnzipPath();\n    return p != null && new File(p).isDirectory();\n}","tryCatchPattern":"try {\n    countRTask.init();\n} catch (TaskInitException e) {\n    MatrixLog.e(TAG, \"point APK-UNZIP-PATH at the extracted dir: %s\", e.getMessage());\n    throw e;\n}","preventionTips":["Never pass the .apk file path as the unzip path.","Derive the unzip directory from the unzip task's output rather than manual config.","Validate isDirectory() before executing resource-counting tasks.","Separate and document the APK-input vs unzip-output config keys."],"tags":["apk-canary","task-init","not-a-directory","unzip-path"],"backgroundTag":"path-is-not-a-directory","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}