{"record":{"id":"74010576d4a5232d","repo":"tauri-apps/tauri","slug":"failed-to-read-android-codegen-directory","errorCode":null,"errorMessage":"failed to read Android codegen directory","messagePattern":"failed to read Android codegen directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri/build.rs","lineNumber":300,"sourceCode":"    }\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\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) {","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri/build.rs#L282-L318","documentation":"While generating Android bindings, tauri's build script lists `mobile/android-codegen` under the crate manifest dir with `fs::read_dir` and panics with this message if the directory cannot be read — normally because it does not exist. The directory should be created/populated as part of the Android codegen workflow.","triggerScenarios":"Building the `tauri` crate with the android/mobile codegen path active when `CARGO_MANIFEST_DIR/mobile/android-codegen` is missing or unreadable — e.g. an incomplete checkout, missing git submodule, or a build for Android without the codegen directory generated.","commonSituations":"Shallow/incomplete git clones or source tarballs that omit the directory; building Android targets without running the codegen steps; typo'd or moved directory after a version upgrade.","solutions":["Ensure a complete source checkout (`git submodule update --init --recursive`, re-clone fully)","Create/populate `crates/tauri/mobile/android-codegen` per the Android build docs before building","Verify you are on a consistent version of the tauri repo/CLI matching the build steps","Check read permissions on the manifest directory"],"exampleFix":"// before\ncargo build --target aarch64-linux-android\n// after\ngit submodule update --init --recursive\n# ensure crates/tauri/mobile/android-codegen exists and is populated\ncargo build --target aarch64-linux-android","handlingStrategy":"validation","validationCode":"let dir = PathBuf::from(env::var(\"CARGO_MANIFEST_DIR\").unwrap()).join(\"mobile/android-codegen\");\nassert!(dir.is_dir(), \"missing Android codegen dir: {}\", dir.display());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clone the repo fully, including submodules","Run the Android codegen steps before building Android targets","Verify directory presence after pulling major tauri version upgrades"],"tags":["android","directory-not-found","build-script","panic","tauri"],"backgroundTag":"directory-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"}