tauri-apps/tauri · error
Failed to canonicalize `WRY_ANDROID_KOTLIN_FILES_OUT_DIR`…
Error message
Failed to canonicalize `WRY_ANDROID_KOTLIN_FILES_OUT_DIR` path {kotlin_out_dir:?} What it means
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.
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.
Example fix
// before: gen/android deleted manually rm -rf src-tauri/gen/android && cargo build --target aarch64-linux-android // after cargo tauri android init && cargo tauri android build
Defensive patterns
Strategy: validation
Validate before calling
# verify kotlin out dir before android build [ -d "$WRY_ANDROID_KOTLIN_FILES_OUT_DIR" ] || cargo tauri android init
Prevention
- 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
When it happens
Trigger: `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.
Common situations: 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.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Android NDK invalid. Make sure the NDK_HOME environment…
- Couldn't get framework filename
- Couldn't get library filename
- does not exist
- failed to extract external binary filename
AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18).
Data as JSON: /api/errors/f6d4e7cf69ddec64.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tauri/build.rs:291
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());
let kotlin_files =
fs::read_dir(kotlin_files_path).expect("failed to read Android codegen directory");
for file in kotlin_files {
let file = file.unwrap();
let content = fs::read_to_string(file.path())
.expect("failed to read kotlin file as string")
.replace("{{package}}", &package)
.replace("{{library}}", &library);
View on GitHub (pinned to 460ec35447)