slint-ui/slint · error

Java compilation failed

Error message

Java compilation failed: {}

What it means

javac ran but exited with a non-zero status; the build script panics with javac's stderr. This is a normal Java compilation failure — syntax/type errors, missing imports, or SDK level incompatibilities in the Java sources generated/compiled for the Android activity backend.

Solutions

  1. Read the stderr shown after the panic message and fix the reported Java errors at the indicated lines
  2. Align the JDK version with the source level expected by the Java sources (install an older/newer JDK as needed)
  3. Verify the Android platform/android.jar exists (`sdkmanager 'platforms;android-XX'`)
  4. Clean the build (`cargo clean -p slint-backend-android-activity`) in case stale generated sources are broken

Example fix

// before: javac error: cannot find symbol KeyEvent
// after
# sdkmanager "platforms;android-33"  # provide the API level the sources expect
export ANDROID_HOME=/opt/android-sdk && cargo build
Defensive patterns

Strategy: validation

Validate before calling

import subprocess
r = subprocess.run(["javac", "-encoding", "UTF-8", "GeneratedFile.java"], capture_output=True)
if r.returncode != 0:
    print(r.stderr.decode())  # fix Java errors before the cargo build

Try / catch

// capture the panic stderr and surface javac diagnostics
match std::panic::catch_unwind(build_android_classes) {
    Ok(()) => {},
    Err(p) => eprintln!("Java build failed: {:?}", p.downcast_ref::<String>()),
}

Prevention

When it happens

Trigger: `.output()` succeeds but `o.status.success()` is false — javac reports errors such as invalid or incompatible source syntax, missing classes on the classpath, or wrong -source/-target for the installed JDK.

Common situations: JDK too new for the source level (e.g. removed APIs); missing android.jar platform; corrupted generated Java source; locale/encoding issues despite the UTF-8 flags.

Related errors


AI-assisted analysis of slint-ui/slint@bb937076de (2026-09-16). Data as JSON: /api/errors/fb64ff00a3d9d6c9. Report an issue: GitHub.

Appendix: source

Thrown at internal/backends/android-activity/build.rs:55

    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}"))
        .output()
        .unwrap_or_else(|e| panic!("Error running D8: {e}"));

    if !o.status.success() {
        eprintln!("Dex conversion failed: {}", String::from_utf8_lossy(&o.stderr));
        let java_home = android_build::java_home().unwrap();

View on GitHub (pinned to bb937076de)