{"record":{"id":"f6d4e7cf69ddec64","repo":"tauri-apps/tauri","slug":"failed-to-canonicalize-wry-android-kotlin-files-out-dir-path","errorCode":null,"errorMessage":"Failed to canonicalize `WRY_ANDROID_KOTLIN_FILES_OUT_DIR` path {kotlin_out_dir:?}","messagePattern":"Failed to canonicalize `WRY_ANDROID_KOTLIN_FILES_OUT_DIR` path (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri/build.rs","lineNumber":291,"sourceCode":"  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());\n      let kotlin_files =\n        fs::read_dir(kotlin_files_path).expect(\"failed to read Android codegen directory\");\n\n      for file in kotlin_files {\n        let file = file.unwrap();\n\n        let content = fs::read_to_string(file.path())\n          .expect(\"failed to read kotlin file as string\")\n          .replace(\"{{package}}\", &package)\n          .replace(\"{{library}}\", &library);\n","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri/build.rs#L273-L309","documentation":"After reading `WRY_ANDROID_KOTLIN_FILES_OUT_DIR` on Android builds, the tauri build script canonicalizes the path to a clean absolute path. If the directory doesn't exist or can't be resolved, the build script panics. The tauri CLI normally creates this directory before invoking cargo, so its absence signals a broken mobile build setup.","triggerScenarios":"`main()` in build.rs calls `PathBuf::from(kotlin_out_dir).canonicalize()`; the env var points to a nonexistent or inaccessible directory because the build wasn't launched via `tauri android build/dev`, or the gen/android directory was deleted/moved.","commonSituations":"Deleting or relocating `src-tauri/gen/android`; running the android target outside the tauri CLI; stale cargo caches referencing an old output dir; path casing/drive issues on Windows after moving the project.","solutions":["Rebuild via `cargo tauri android build` / `cargo tauri android dev` so the CLI recreates the Kotlin files output directory.","Run `cargo tauri android init` to regenerate a missing src-tauri/gen/android directory.","Verify the WRY_ANDROID_KOTLIN_FILES_OUT_DIR value points to an existing directory (create it if missing).","Clean and rebuild from the project root if the project was moved, so stale absolute paths are refreshed."],"exampleFix":"// before: gen/android deleted manually\nrm -rf src-tauri/gen/android && cargo build --target aarch64-linux-android\n// after\ncargo tauri android init && cargo tauri android build","handlingStrategy":"validation","validationCode":"# verify kotlin out dir before android build\n[ -d \"$WRY_ANDROID_KOTLIN_FILES_OUT_DIR\" ] || cargo tauri android init","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't delete or move src-tauri/gen/android manually","Re-run `cargo tauri android init` after restructuring the project","Build via the tauri CLI which creates the output directory before invoking cargo","Clean stale cargo caches after moving a project on disk"],"tags":["android","filesystem","build","path"],"backgroundTag":"file-not-found","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"}