{"record":{"id":"816af8f9be872821","repo":"Tencent/matrix","slug":"the-resource-declarations-file-r-txt-is-not-l","errorCode":null,"errorMessage":"---The Resource declarations file 'R.txt' is not legal!","messagePattern":"---The Resource declarations file 'R\\.txt' is not legal!","errorType":"exception","errorClass":"TaskInitException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-apk-canary/src/main/java/com/tencent/matrix/apk/model/task/UnusedResourcesTask.java","lineNumber":112,"sourceCode":"        unusedResSet = new HashSet<>();\n        nonValueReferences = new HashMap<>();\n        visitPath = new Stack<String>();\n    }\n\n    @Override\n    public void init() throws TaskInitException {\n        super.init();\n\n        String inputPath = config.getUnzipPath();\n        if (Util.isNullOrNil(inputPath)) {\n            throw new TaskInitException(TAG + \"---APK-UNZIP-PATH can not be null!\");\n        }\n        if (!params.containsKey(JobConstants.PARAM_R_TXT) || Util.isNullOrNil(params.get(JobConstants.PARAM_R_TXT))) {\n            throw new TaskInitException(TAG + \"---The File 'R.txt' can not be null!\");\n        }\n        resourceTxt = new File(params.get(JobConstants.PARAM_R_TXT));\n        if (!FileUtil.isLegalFile(resourceTxt)) {\n            throw new TaskInitException(TAG + \"---The Resource declarations file 'R.txt' is not legal!\");\n        }\n        inputFile = new File(inputPath);\n        if (!inputFile.exists()) {\n            throw new TaskInitException(TAG + \"---APK-UNZIP-PATH '\" + inputPath + \"' is not exist!\");\n        } else if (!inputFile.isDirectory()) {\n            throw new TaskInitException(TAG + \"---APK-UNZIP-PATH '\" + inputPath + \"' is not directory!\");\n        }\n        if (!Util.isNullOrNil(config.getMappingFilePath())) {\n            mappingTxt = new File(config.getMappingFilePath());\n            if (!FileUtil.isLegalFile(mappingTxt)) {\n                throw new TaskInitException(TAG + \"---The Proguard mapping file 'mapping.txt' is not legal!\");\n            }\n        }\n        if (params.containsKey(JobConstants.PARAM_IGNORE_RESOURCES_LIST) && !Util.isNullOrNil(params.get(JobConstants.PARAM_IGNORE_RESOURCES_LIST))) {\n            String[] ignoreRes = params.get(JobConstants.PARAM_IGNORE_RESOURCES_LIST).split(\",\");\n            for (String ignore : ignoreRes) {\n                ignoreSet.add(Util.globToRegexp(ignore));\n            }","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-apk-canary/src/main/java/com/tencent/matrix/apk/model/task/UnusedResourcesTask.java#L94-L130","documentation":"UnusedResourcesTask.init() throws TaskInitException when the R.txt path provided in params points to a file that is not legal (missing, not a file, or unreadable per FileUtil.isLegalFile). The path was present but the file itself is invalid.","triggerScenarios":"PARAM_R_TXT set to a stale/typo path, the file was cleaned before the task ran, or the path points to a directory instead of R.txt.","commonSituations":"Running check between clean and build (R.txt not yet generated), CI ordering issues, or AGP versions with different intermediates paths.","solutions":["Confirm the R.txt file exists at the configured path before running the task","Build the app first (assembleDebug) so R.txt is generated, then run the check","Fix the path — it must point to the R.txt file itself, not its directory"],"exampleFix":"// before\nparams.put(JobConstants.PARAM_R_TXT, \"build/intermediates/R.txt\"); // stale path\n// after\nparams.put(JobConstants.PARAM_R_TXT, \"app/build/intermediates/runtime_symbol_list/debug/R.txt\"); // verify file exists","handlingStrategy":"validation","validationCode":"File rTxt = new File(params.get(JobConstants.PARAM_R_TXT));\nif (!rTxt.isFile() || !rTxt.canRead()) throw new IllegalStateException(\"R.txt not a readable file\");","typeGuard":null,"tryCatchPattern":"try {\n    task.init();\n} catch (TaskInitException e) {\n    log.error(\"invalid R.txt: \" + e.getMessage());\n}","preventionTips":["Regenerate R.txt after clean builds","Avoid hardcoding intermediates paths — resolve from AGP APIs","Check file existence in CI before invoking the checker"],"tags":["android","apk-analysis","invalid-file"],"backgroundTag":"file-not-found","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"}