{"record":{"id":"23a431da7e9eee29","repo":"tauri-apps/tauri","slug":"var-is-not-set-which-is-needed-to-generate-th","errorCode":null,"errorMessage":"`{var}` is not set, which is needed to generate the kotlin files for android.","messagePattern":"`(.+?)` is not set, which is needed to generate the kotlin files for android\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri/build.rs","lineNumber":280,"sourceCode":"  let out_dir = PathBuf::from(env::var_os(\"OUT_DIR\").unwrap());\n\n  let checked_features_out_path = out_dir.join(\"checked_features\");\n  // file is used by a unit test in src/lib.rs to check that the features checked do exist in the Cargo.toml\n  std::fs::write(checked_features_out_path, checked_features.join(\",\"))\n    .expect(\"failed to write checked_features file\");\n\n  // workaround needed to prevent `STATUS_ENTRYPOINT_NOT_FOUND` error in tests\n  // see https://github.com/tauri-apps/tauri/pull/4383#issuecomment-1212221864\n  let target_env = std::env::var_os(\"CARGO_CFG_TARGET_ENV\");\n  let is_tauri_workspace = std::env::var_os(\"__TAURI_WORKSPACE__\").is_some_and(|v| v == \"true\");\n  if is_tauri_workspace && target_os == \"windows\" && target_env.is_some_and(|trgt| trgt == \"msvc\") {\n    embed_manifest_for_tests();\n  }\n\n  if target_os == \"android\" {\n    fn env_var(var: &str) -> String {\n      std::env::var(var).unwrap_or_else(|_| {\n        panic!(\"`{var}` is not set, which is needed to generate the kotlin files for android.\")\n      })\n    }\n\n    if let Some(kotlin_out_dir) = std::env::var_os(\"WRY_ANDROID_KOTLIN_FILES_OUT_DIR\") {\n      let package = env_var(\"WRY_ANDROID_PACKAGE\");\n      let library = env_var(\"WRY_ANDROID_LIBRARY\");\n\n      let kotlin_out_dir = PathBuf::from(&kotlin_out_dir)\n        .canonicalize()\n        .unwrap_or_else(move |_| {\n          panic!(\n            \"Failed to canonicalize `WRY_ANDROID_KOTLIN_FILES_OUT_DIR` path {kotlin_out_dir:?}\"\n          )\n        });\n\n      let kotlin_files_path =\n        PathBuf::from(env_var(\"CARGO_MANIFEST_DIR\")).join(\"mobile/android-codegen\");\n      println!(\"cargo:rerun-if-changed={}\", kotlin_files_path.display());","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri/build.rs#L262-L298","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Build through the tauri CLI: `cargo tauri android init` then `cargo tauri android build` or `cargo tauri android dev`, which set WRY_ANDROID_* variables.","Ensure the tauri CLI version matches your `tauri`/`wry` crate versions (e.g. `cargo install tauri-cli --version <same minor>`).","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.","Ignore the error from rust-analyzer for the android target by configuring it to skip the mobile targets."],"exampleFix":"// before\ncargo build --target aarch64-linux-android\n// after\ncargo tauri android build --target aarch64","handlingStrategy":"validation","validationCode":"// shell check before building android target\n[ -n \"$WRY_ANDROID_PACKAGE\" ] && [ -n \"$WRY_ANDROID_LIBRARY\" ] && [ -n \"$WRY_ANDROID_KOTLIN_FILES_OUT_DIR\" ] || { echo 'run via cargo tauri android build'; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always build Android targets through `cargo tauri android build/dev`","Keep tauri-cli version in lockstep with tauri/wry crate versions","Exclude mobile targets from rust-analyzer/IDE cargo invocations"],"tags":["android","build","env-var","mobile"],"backgroundTag":"missing-env-var","analyzedSha":"460ec35447493200d64290dd7f015d5a91d0fd58","analyzedAt":"2026-09-18T23:55:51.277Z","contentChangedAt":"2026-09-18T23:55:51.277Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}