{"record":{"id":"c0620fec684188dd","repo":"tauri-apps/tauri","slug":"failed-to-write-kotlin-file","errorCode":null,"errorMessage":"Failed to write kotlin file","messagePattern":"Failed to write kotlin file","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri/build.rs","lineNumber":318,"sourceCode":"        });\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\"),\n        tauri_proguard,\n      )\n      .expect(\"failed to write proguard-tauri.pro\");\n    }\n\n    let lib_path =","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/tauri-apps/tauri/blob/52e4b6e71d8632a7e648f866c442e287ecddee34/crates/tauri/build.rs#L300-L336","documentation":"During Android builds, tauri's build script reads Kotlin templates, substitutes {{package}} and {{library}}, and writes each into the Android project's Kotlin output directory (from the TAURI_ANDROID_* env vars). write_if_changed fails when that output directory does not exist or is not writable.","triggerScenarios":"TAURI_ANDROID_PROJECT_PATH / kotlin out dir env vars pointing at an Android project whose generated Kotlin source directory is missing (partially generated, manually pruned, stale env var).","commonSituations":"Running the Android build against a hand-modified or partially regenerated gen/android project; env vars left pointing at a moved or deleted folder.","solutions":["Regenerate the Android project: tauri android init.","Verify the Kotlin output directory exists and is writable (create_dir_all on it succeeds).","Re-point TAURI_ANDROID_* env vars at the current gen/android folder."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before the android build, make sure the kotlin out dir exists\nif let Some(kotlin_out) = std::env::var_os(\"TAURI_ANDROID_KOTLIN_OUT_DIR\") {\n    std::fs::create_dir_all(std::path::PathBuf::from(kotlin_out))\n        .expect(\"kotlin out dir must exist and be writable\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Regenerate the Android project with tauri android init after config changes.","Do not hand-prune generated directories under gen/android.","Keep TAURI_ANDROID_* env vars pointing at the current project."],"tags":["tauri","android","build-script","codegen","kotlin"],"backgroundTag":"build-script-write-failed","analyzedSha":"52e4b6e71d8632a7e648f866c442e287ecddee34","analyzedAt":"2026-08-20T13:59:20.734Z","contentChangedAt":"2026-08-20T13:59:20.734Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}