Tencent/matrix · error · TaskInitException
---The Resource declarations file 'R.txt' is not legal!
Error message
---The Resource declarations file 'R.txt' is not legal!
What it means
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.
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
Example fix
// before params.put(JobConstants.PARAM_R_TXT, "build/intermediates/R.txt"); // stale path // after params.put(JobConstants.PARAM_R_TXT, "app/build/intermediates/runtime_symbol_list/debug/R.txt"); // verify file exists
Defensive patterns
Strategy: validation
Validate before calling
File rTxt = new File(params.get(JobConstants.PARAM_R_TXT));
if (!rTxt.isFile() || !rTxt.canRead()) throw new IllegalStateException("R.txt not a readable file"); Try / catch
try {
task.init();
} catch (TaskInitException e) {
log.error("invalid R.txt: " + e.getMessage());
} Prevention
- Regenerate R.txt after clean builds
- Avoid hardcoding intermediates paths — resolve from AGP APIs
- Check file existence in CI before invoking the checker
When it happens
Trigger: 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.
Common situations: Running check between clean and build (R.txt not yet generated), CI ordering issues, or AGP versions with different intermediates paths.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- e.getMessage()
- TAG + "---APK-UNZIP-PATH can not be null!"
- TAG + "---The File 'R.txt' can not be null!"
- ---APK-UNZIP-PATH ' ' is not exist!
- ---APK-UNZIP-PATH ' ' is not directory!
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/816af8f9be872821.
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:112
unusedResSet = new HashSet<>();
nonValueReferences = new HashMap<>();
visitPath = new Stack<String>();
}
@Override
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));
}View on GitHub (pinned to 3b8293bd65)