skylot/jadx · error · JadxRuntimeException
Unknown variable: '{}' in template: {}
Error message
Unknown variable: '{}' in template: {} What it means
Thrown as JadxRuntimeException by TemplateFile.processVar() when values.get(varName) returns null, meaning the template references a variable that was never registered via TemplateFile.add(name, value). The template engine requires every '{{variable}}' placeholder to have a corresponding add() call before build()/save(). The error includes both the variable name and the template file name.
Source
Thrown at jadx-core/src/main/java/jadx/core/export/TemplateFile.java:159
case START:
parser.state = State.NONE;
return "{" + ch;
case END:
throw new JadxRuntimeException("Expected variable end: '" + parser.curVariable
+ "' (missing second '}')");
}
break;
}
parser.skip = false;
return null;
}
private String processVar(String varName, boolean rawValue) {
String str = values.get(varName);
if (str == null) {
throw new JadxRuntimeException("Unknown variable: '" + varName
+ "' in template: " + templateName);
}
if (!rawValue) {
Function<String, String> sanitizer = valueSanitizer;
if (sanitizer != null) {
return sanitizer.apply(str);
}
}
return str;
}
}
View on GitHub (pinned to e738a26571)
Solutions
- Check the template file (named in the error message) for all '{{...}}' placeholders and ensure each has a matching tmpl.add() call.
- Verify variable name spelling and case match exactly between template and code.
- If using stock jadx templates, report the bug with the template name and variable name from the error.
- For custom templates, add a tmpl.add(varName, value) for every referenced variable, or remove unused placeholders from the template.
Example fix
// before — template has {{version}} but code does not add it
TemplateFile tmpl = TemplateFile.fromResources("/export/build.tmpl");
tmpl.add("projectName", name);
tmpl.save(file); // error: Unknown variable 'version'
// after — add all referenced variables
TemplateFile tmpl = TemplateFile.fromResources("/export/build.tmpl");
tmpl.add("projectName", name);
tmpl.add("version", version);
tmpl.save(file); Defensive patterns
Strategy: validation
Validate before calling
// Before rendering, collect all variable names from the template
// and ensure each is registered via add()
Set<String> requiredVars = extractTemplateVariables(templateContent);
for (String var : requiredVars) {
if (!values.containsKey(var)) {
throw new IllegalStateException("Missing template variable: " + var);
}
} Try / catch
try {
tmpl.save(outFile);
} catch (JadxRuntimeException e) {
if (e.getMessage().contains("Unknown variable")) {
LOG.error("Template variable not provided: {}", e.getMessage());
// Add the missing variable or fix the template
} else {
throw e;
}
} Prevention
- Call tmpl.add(varName, value) for every '{{varName}}' placeholder in the template.
- Match variable names exactly (case-sensitive, no trailing whitespace).
- When updating templates, update the generator code that supplies variables in lockstep.
- Add a test that renders each template with all expected variables to catch mismatches early.
When it happens
Trigger: A template file contains '{{projectName}}' but the calling code never calls tmpl.add("projectName", value). This occurs when a template is updated to reference a new variable but the generator code is not updated to supply it, or when a variable name has a typo mismatch between template and code.
Common situations: Internal jadx bug where a template and its generator code are out of sync. Custom export templates referencing variables the generator does not provide. Case-sensitivity or whitespace issues in variable names (note: variable names are collected character-by-character, so embedded whitespace matters).
Related errors
- Duplicate plugin id: {}, class {}
- Failed to generate gradle files
- Resource not found: {}
- Template already processed
- Expected variable end: '{}' (missing second '}')
AI-assisted analysis of skylot/jadx@e738a26571 (2026-08-14).
Data as JSON: /api/errors/b241ddea20d33a37.
Report an issue: GitHub.