slint-ui/slint · error
Could not generate the java compiler command
Error message
Could not generate the java compiler command: {e} What it means
The android-activity build script builds a javac command via the android-build helper and fails when `JavaBuild::command()` cannot construct the compiler invocation — typically because a JDK/javac toolchain cannot be located or configured. The build aborts before even attempting compilation.
Solutions
- Install a full JDK (not a JRE) so javac exists (e.g. apt install openjdk-17-jdk or sdkman)
- Set JAVA_HOME to the JDK root and ensure it's exported in the build environment
- Verify `javac -version` works in the shell running cargo
- Check the android SDK/platform setup (android_jar lookup precedes this) matches requirements
Example fix
// before export JAVA_HOME=/usr/lib/jvm/java-17-jre // after export JAVA_HOME=/usr/lib/jvm/java-17-jdk export PATH="$JAVA_HOME/bin:$PATH"
Defensive patterns
Strategy: validation
Validate before calling
import shutil, os
assert shutil.which("javac"), "javac not found; install a JDK"
assert "jdk" in os.environ.get("JAVA_HOME", "").lower() or os.path.exists(os.path.join(os.environ.get("JAVA_HOME", ""), "bin", "javac")), "JAVA_HOME must point to a JDK" Prevention
- Install a JDK, not just a JRE, in build images
- Export JAVA_HOME consistently in CI and locally
- Verify toolchain setup with `javac -version` before building
When it happens
Trigger: `JavaBuild::new()...command()` returns Err — no JAVA_HOME / JDK found, javac missing from PATH resolution, or invalid configuration passed to JavaBuild.
Common situations: Docker/CI images without a JDK installed; JAVA_HOME pointing at a JRE (no javac); broken Android SDK/NDK setup altering tool discovery.
Related errors
AI-assisted analysis of slint-ui/slint@bb937076de (2026-09-16).
Data as JSON: /api/errors/d677ea3abb0b3c9d.
Report an issue: GitHub.
Appendix: source
Thrown at internal/backends/android-activity/build.rs:49
std::fs::create_dir_all(&out_class_dir)
.unwrap_or_else(|e| panic!("Cannot create output directory {out_class_dir:?} - {e}"));
let android_jar = android_build::android_jar(None).expect("No Android platforms found");
// Compile the Java file into .class files
let o = JavaBuild::new()
.file(&java_src_path)
.class_path(&android_jar)
.classes_out_dir(&out_class_dir)
.java_source_version(8)
.java_target_version(8)
.debug_info(android_build::DebugInfo {
line_numbers: !release_mode,
variables: !release_mode,
source_files: !release_mode,
})
.command()
.unwrap_or_else(|e| panic!("Could not generate the java compiler command: {e}"))
.args(["-encoding", "UTF-8"])
.output()
.unwrap_or_else(|e| panic!("Could not run the java compiler: {e}"));
if !o.status.success() {
panic!("Java compilation failed: {}", String::from_utf8_lossy(&o.stderr));
}
let o = Dexer::new()
.android_jar(&android_jar)
.class_path(&out_class_dir)
.collect_classes(&out_class_dir)
.unwrap()
.release(release_mode)
.android_min_api(20) // disable multidex for single dex file output
.out_dir(out_dir)
.command()
.unwrap_or_else(|e| panic!("Could not generate the D8 command: {e}"))View on GitHub (pinned to bb937076de)