tauri-apps/tauri · error

` ` is not set, which is needed to generate the kotlin…

Error message

`{var}` is not set, which is needed to generate the kotlin files for android.

What it means

When compiling the `tauri` crate for an Android target, its build script needs WRY/CARGO-provided environment variables (WRY_ANDROID_PACKAGE, WRY_ANDROID_LIBRARY, etc.) that the tauri CLI sets up. If one is missing, the build script panics because Kotlin codegen cannot proceed. Building for Android without going through `tauri android build/dev` causes this.

Solutions

  1. Build through the tauri CLI: `cargo tauri android init` then `cargo tauri android build` or `cargo tauri android dev`, which set WRY_ANDROID_* variables.
  2. Ensure the tauri CLI version matches your `tauri`/`wry` crate versions (e.g. `cargo install tauri-cli --version <same minor>`).
  3. If you must use cargo directly, export WRY_ANDROID_PACKAGE, WRY_ANDROID_LIBRARY, WRY_ANDROID_KOTLIN_FILES_OUT_DIR and the NDK variables yourself exactly as the CLI does.
  4. Ignore the error from rust-analyzer for the android target by configuring it to skip the mobile targets.

Example fix

// before
cargo build --target aarch64-linux-android
// after
cargo tauri android build --target aarch64
Defensive patterns

Strategy: validation

Validate before calling

// shell check before building android target
[ -n "$WRY_ANDROID_PACKAGE" ] && [ -n "$WRY_ANDROID_LIBRARY" ] && [ -n "$WRY_ANDROID_KOTLIN_FILES_OUT_DIR" ] || { echo 'run via cargo tauri android build'; exit 1; }

Prevention

When it happens

Trigger: `build.rs` `main()` for target_os = "android" calls `env_var("WRY_ANDROID_PACKAGE")` / `env_var("WRY_ANDROID_LIBRARY")`; the variable is absent because the build was invoked with plain `cargo build` instead of the tauri CLI, or the tauri CLI version mismatches the wry/tauri crates.

Common situations: Running `cargo build --target aarch64-linux-android` directly; IDE/Rust-analyzer building the android target; mismatched tauri CLI and crate versions after an upgrade; NDK/toolchain env not exported.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18). Data as JSON: /api/errors/23a431da7e9eee29. Report an issue: GitHub.

Appendix: source

Thrown at crates/tauri/build.rs:280

  let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());

  let checked_features_out_path = out_dir.join("checked_features");
  // file is used by a unit test in src/lib.rs to check that the features checked do exist in the Cargo.toml
  std::fs::write(checked_features_out_path, checked_features.join(","))
    .expect("failed to write checked_features file");

  // workaround needed to prevent `STATUS_ENTRYPOINT_NOT_FOUND` error in tests
  // see https://github.com/tauri-apps/tauri/pull/4383#issuecomment-1212221864
  let target_env = std::env::var_os("CARGO_CFG_TARGET_ENV");
  let is_tauri_workspace = std::env::var_os("__TAURI_WORKSPACE__").is_some_and(|v| v == "true");
  if is_tauri_workspace && target_os == "windows" && target_env.is_some_and(|trgt| trgt == "msvc") {
    embed_manifest_for_tests();
  }

  if target_os == "android" {
    fn env_var(var: &str) -> String {
      std::env::var(var).unwrap_or_else(|_| {
        panic!("`{var}` is not set, which is needed to generate the kotlin files for android.")
      })
    }

    if let Some(kotlin_out_dir) = std::env::var_os("WRY_ANDROID_KOTLIN_FILES_OUT_DIR") {
      let package = env_var("WRY_ANDROID_PACKAGE");
      let library = env_var("WRY_ANDROID_LIBRARY");

      let kotlin_out_dir = PathBuf::from(&kotlin_out_dir)
        .canonicalize()
        .unwrap_or_else(move |_| {
          panic!(
            "Failed to canonicalize `WRY_ANDROID_KOTLIN_FILES_OUT_DIR` path {kotlin_out_dir:?}"
          )
        });

      let kotlin_files_path =
        PathBuf::from(env_var("CARGO_MANIFEST_DIR")).join("mobile/android-codegen");
      println!("cargo:rerun-if-changed={}", kotlin_files_path.display());

View on GitHub (pinned to 460ec35447)