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

  1. Ensure a complete source checkout (`git submodule update --init --recursive`, re-clone fully)
  2. Create/populate `crates/tauri/mobile/android-codegen` per the Android build docs before building
  3. Verify you are on a consistent version of the tauri repo/CLI matching the build steps
  4. 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

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


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)