{"record":{"id":"0bf1de7f7717033e","repo":"tauri-apps/tauri","slug":"failed-to-read-kotlin-file-as-string","errorCode":null,"errorMessage":"failed to read kotlin file as string","messagePattern":"failed to read kotlin file as string","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri/build.rs","lineNumber":306,"sourceCode":"      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\n        let out_path = kotlin_out_dir.join(file.file_name());\n        // Overwrite only if changed to not trigger rebuilds\n        write_if_changed(&out_path, &content).expect(\"Failed to write kotlin file\");\n\n        println!(\"cargo:rerun-if-changed={}\", out_path.display());\n      }\n    }\n\n    if let Some(project_dir) = env::var_os(\"TAURI_ANDROID_PROJECT_PATH\").map(PathBuf::from) {\n      let package_unescaped = env::var(\"TAURI_ANDROID_PACKAGE_UNESCAPED\")\n        .unwrap_or_else(|_| env_var(\"WRY_ANDROID_PACKAGE\").replace('`', \"\"));\n      let tauri_proguard =\n        include_str!(\"./mobile/proguard-tauri.pro\").replace(\"$PACKAGE\", &package_unescaped);\n      std::fs::write(\n        project_dir.join(\"app\").join(\"proguard-tauri.pro\"),","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri/build.rs#L288-L324","documentation":"This is a build-time panic from the Tauri crate's build script. During an Android build, the script reads every .kt template file from the Android codegen directory and substitutes {{package}}/{{library}} placeholders. If fs::read_to_string fails on any of those files (file missing, not readable, invalid UTF-8), the build script panics with this message and aborts compilation of the crate.","triggerScenarios":"Running `cargo build` for an Android target while a file inside the Android codegen directory pointed to by kotlin_files_path cannot be read: it was deleted between read_dir and read, is unreadable due to filesystem permissions, or contains invalid UTF-8.","commonSituations":"A partially-checked-out or corrupted tauri source tree, a broken symlink inside the mobile android-codegen directory, antivirus/indexing tools locking files during build on Windows, or filesystem permission issues after running the build as a different user (e.g. sudo).","solutions":["Verify the tauri source checkout is intact (git status / re-clone) so all codegen .kt files exist","Check permissions on the kotlin_files_path directory and its files; ensure the build user can read them","Ensure no other process (antivirus, IDE sync) is locking or modifying the files during build","Update or pin the Tauri version; if caused by a packaging bug, report it to tauri-apps/tauri"],"exampleFix":"// cargo config: force a clean rebuild after fixing file state\n// before\nrm -rf target && cargo tauri android build\n// after\ncargo tauri android build","handlingStrategy":"validation","validationCode":"let p = std::path::Path::new(\"crates/tauri/mobile/android-codegen\");\nassert!(p.is_dir(), \"codegen dir missing\");\nfor f in std::fs::read_dir(p).unwrap() {\n    let f = f.unwrap().path();\n    assert!(f.is_file(), \"not a file: {}\", f.display());\n    assert!(std::fs::read(&f).is_ok(), \"unreadable: {}\", f.display());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the tauri checkout intact; avoid partial tarball downloads","Never run builds with sudo that change file ownership","Exclude source trees from antivirus real-time scanning on Windows"],"tags":["build-script","android","filesystem","io"],"backgroundTag":"file-read-failed","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"}