androidrustresourcestauri

How to use Tauri Resource Files properly on Android


I'm currently trying to write an android app using tauri that is required to access font resource files.

However, when trying to access the file using following code snippet, I get a NotFound error.

let resource_path = app_handle
        .path()
        .resolve(format!("fonts/{}", name), BaseDirectory::Resource)
        .expect("failed to resolve resource");
let mut file = File::open(&resource_path).expect(&format!("Failed to open font file {}", resource_path.as_path().to_str().unwrap()));
10-19 16:22:58.189 19486 19600 I RustStdoutStderr: thread '<unnamed>' panicked at src\lib.rs:85:47:
10-19 16:22:58.189 19486 19600 I RustStdoutStderr: Failed to open font file asset://localhost/fonts/Calibri-Regular.ttf: Os { code: 2, kind: NotFound, message: "No such file or directory" }

I tried the same code on windows and everything worked fine, android seems to handle resources differently, but I normally do not develop android applications, so I'm not sure how to approach this. Any help is appreciated :)


Solution

  • There is currently a known issue for this: https://github.com/tauri-apps/tauri/issues/11823

    It currently doesn't seem to be possible to properly add resource files on Android. I haven't found any workaround yet, but I asked in the linked GH issue above.

    My Android App just crashed and it took me some time to figure out that this is related to file reading.