Tencent/matrix · error · TaskInitException
TAG + "---The File 'R.txt' can not be null!"
Error message
TAG + "---The File 'R.txt' can not be null!"
What it means
UnusedResourcesTask.init() throws TaskInitException when params contains no R.txt path or the value is empty. R.txt (resource declarations) is required to map resource names to IDs when detecting unused resources.
Solutions
- Pass the R.txt path: params.put(JobConstants.PARAM_R_TXT, path/to/R.txt) or -R <path> on the CLI
- Ensure your app module generates R.txt (AGP generates it in build/intermediates for application modules)
- Point to the R.txt of the application (app) module, not a library
Example fix
// before job.addTask(TaskFactory.TASK_TYPE_UNUSED_RESOURCES); // after Map<String, String> params = new HashMap<>(); params.put(JobConstants.PARAM_R_TXT, "/project/app/build/intermediates/runtime_symbol_list/debug/R.txt"); job.addTask(TaskFactory.TASK_TYPE_UNUSED_RESOURCES, params);
Defensive patterns
Strategy: validation
Validate before calling
String rTxt = params.get(JobConstants.PARAM_R_TXT);
if (rTxt == null || rTxt.isEmpty()) throw new IllegalArgumentException("PARAM_R_TXT required");
if (!new File(rTxt).exists()) throw new IllegalArgumentException("R.txt missing: " + rTxt); Try / catch
try {
job.addTask(TaskFactory.TASK_TYPE_UNUSED_RESOURCES, params);
} catch (TaskInitException e) {
log.error("R.txt param missing: " + e.getMessage());
} Prevention
- Always assemble the app before running ApkChecker
- Point PARAM_R_TXT at the app module's generated R.txt
- Document required params per task in your plugin wrapper
When it happens
Trigger: Calling addTask for UnusedResourcesTask without JobConstants.PARAM_R_TXT, or passing an empty string for it.
Common situations: AGP version changes where R.txt generation is missing/disabled (e.g., buildFeatures missing or non-Application modules), or forgetting the -R parameter on the ApkChecker CLI.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- e.getMessage()
- TAG + "---APK-UNZIP-PATH can not be null!"
- ---The Resource declarations file 'R.txt' is not legal!
- ---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/4af520141fbc6c02.
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:108
resguardMap = new HashMap<>();
resourceDefMap = new HashMap<>();
styleableMap = new HashMap<>();
resourceRefSet = new HashSet<>();
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))) {View on GitHub (pinned to 3b8293bd65)