October 21, 2024
Chicago 12, Melborne City, USA
Android

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.

  • I added these files in my src-tauri directory within a fonts folder.
  • In my tauri.conf.json I set the "bundle": {"resources": ["fonts/*"]} specifier
  • I checked the targe > debug directories and the fonts folder + font files were all created

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 🙂



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video