{"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":312,"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":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri/build.rs#L294-L330","documentation":"Build-script panic raised when write_if_changed fails to persist a generated Kotlin file into the codegen output directory. The Tauri build script generates Android Kotlin sources from templates and writes them to OUT_DIR (only overwriting when content changed to avoid rebuild churn). A failure here means the generated file could not be written.","triggerScenarios":"The kotlin output directory (out_path) is not writable: OUT_DIR missing or deleted mid-build, disk full, read-only filesystem, or permission denied on the destination path.","commonSituations":"Out-of-disk errors on CI runners, target/ directory owned by root after a sudo build, a read-only mounted workspace, or concurrent builds racing on the same OUT_DIR.","solutions":["Free disk space and confirm the filesystem is writable","Fix ownership/permissions of the target directory (e.g. sudo chown -R $(whoami) target)","Delete the target directory and rebuild to regenerate a clean OUT_DIR","Avoid running multiple cargo builds concurrently against the same target dir"],"exampleFix":"// before\nsudo cargo tauri android build   # target/ now owned by root\n// after\nsudo chown -R $(whoami) target\ncargo tauri android build","handlingStrategy":"validation","validationCode":"let dir = std::path::Path::new(&out_dir);\nassert!(dir.is_dir(), \"OUT_DIR missing\");\nlet probe = dir.join(\".write-test\");\nstd::fs::write(&probe, b\"\").expect(\"OUT_DIR not writable\");\nlet _ = std::fs::remove_file(&probe);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Monitor CI disk space","One build per target directory","Avoid sudo cargo builds; fix ownership instead"],"tags":["build-script","android","filesystem","write"],"backgroundTag":"file-write-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"}