skylot/jadx · error · JadxRuntimeException

Failed to generate gradle files

Error message

Failed to generate gradle files

What it means

Thrown as JadxRuntimeException by SimpleJavaGradleGenerator.generateFiles() wrapping any exception during settings.gradle.kts or build.gradle.kts generation. This generator handles the SIMPLE_JAVA export type (non-Android projects). The original exception is attached as the cause for diagnosis.

Source

Thrown at jadx-core/src/main/java/jadx/core/export/gen/SimpleJavaGradleGenerator.java:44

		this.projectDir = projectDir;
		this.resources = resources;
	}

	@Override
	public void init() {
		appDir = new File(projectDir, "app");
		File srcOutDir = new File(appDir, "src/main/java");
		File resOutDir = new File(appDir, "src/main/resources");
		outDirs = new OutDirs(srcOutDir, resOutDir);
	}

	@Override
	public void generateFiles() {
		try {
			saveSettingsGradle();
			saveBuildGradle();
		} catch (Exception e) {
			throw new JadxRuntimeException("Failed to generate gradle files", e);
		}
	}

	private void saveSettingsGradle() throws IOException {
		TemplateFile tmpl = loadGradleTemplate("/export/java/settings.gradle.kts.tmpl");
		tmpl.add("projectName", GradleGeneratorTools.guessProjectName(root));
		tmpl.save(new File(projectDir, "settings.gradle.kts"));
	}

	private void saveBuildGradle() throws IOException {
		TemplateFile tmpl = loadGradleTemplate("/export/java/build.gradle.kts.tmpl");
		tmpl.save(new File(appDir, "build.gradle.kts"));
	}

	private TemplateFile loadGradleTemplate(String templatePath) throws FileNotFoundException {
		TemplateFile tmpl = TemplateFile.fromResources(templatePath);
		IJadxSecurity security = root.getArgs().getSecurity();
		tmpl.setValueSanitizer(str -> security.sanitizeString(str, SanitizeType.GRADLE_KOTLIN));

View on GitHub (pinned to e738a26571)

Solutions

  1. Inspect getCause() to identify the root exception type.
  2. Verify the output project directory is writable.
  3. Ensure the jadx distribution is complete (templates under /export/java/ must be present in the jadx-core JAR).
  4. If the cause is an unknown template variable, report to jadx developers.
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify template resources are present before export
if (TemplateFile.class.getResource("/export/java/settings.gradle.kts.tmpl") == null) {
    throw new IllegalStateException("Gradle templates missing from classpath");
}

Try / catch

try {
    exportGradle.generateGradleFiles();
} catch (JadxRuntimeException e) {
    Throwable cause = e.getCause();
    LOG.error("Simple Java Gradle export failed. Root cause: {}", cause.getMessage(), cause);
}

Prevention

When it happens

Trigger: Any exception during saveSettingsGradle() or saveBuildGradle(). Common causes: IOException from file writes, FileNotFoundException if the /export/java/*.kts.tmpl template resources are missing from the classpath, or JadxRuntimeException from template variable resolution failures (unknown variable, malformed template).

Common situations: Exporting a plain Java JAR as a Gradle project. Fails with missing templates if the jadx-core JAR is incomplete or the resources were stripped. Fails with I/O errors on read-only or full output directories.

Related errors


AI-assisted analysis of skylot/jadx@e738a26571 (2026-08-14). Data as JSON: /api/errors/fed395b97f8dee54. Report an issue: GitHub.