tauri-apps/tauri · error
failed to read Android codegen directory
Error message
failed to read Android codegen directory
What it means
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.
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
Example fix
// before cargo build --target aarch64-linux-android // after git submodule update --init --recursive # ensure crates/tauri/mobile/android-codegen exists and is populated cargo build --target aarch64-linux-android
Defensive patterns
Strategy: validation
Validate before calling
let dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("mobile/android-codegen");
assert!(dir.is_dir(), "missing Android codegen dir: {}", dir.display()); Prevention
- Clone the repo fully, including submodules
- Run the Android codegen steps before building Android targets
- Verify directory presence after pulling major tauri version upgrades
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to canonicalize global API script path
- failed to parse plugin global API script paths
- failed to read plugin global API script paths
- failed to serialize global API script paths
- failed to write checked_features file
AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18).
Data as JSON: /api/errors/74010576d4a5232d.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tauri/build.rs:300
}
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);
let out_path = kotlin_out_dir.join(file.file_name());
// Overwrite only if changed to not trigger rebuilds
write_if_changed(&out_path, &content).expect("Failed to write kotlin file");
println!("cargo:rerun-if-changed={}", out_path.display());
}
}
if let Some(project_dir) = env::var_os("TAURI_ANDROID_PROJECT_PATH").map(PathBuf::from) {View on GitHub (pinned to 460ec35447)