DioxusLabs / dioxus

Fullstack GUI library for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
19.33k stars 736 forks source link

Accessing bundled resources in android apps #2183

Open LaurentMazare opened 3 months ago

LaurentMazare commented 3 months ago

Problem

I'm trying to bundle some data file in a dioxus app but when trying to access the file I get some file not found error. Not sure if this is supposed to be supported at the moment, also I might well be doing something pretty wrong here.

Steps To Reproduce

See this gist for a small repro.

Basically I created a test.txt file in my project directory, added the following to my Cargo.toml:

[bundle]
resources = ["test.txt"]

And in the app code I'm trying to read the file via:

    let content = std::fs::read_to_string("test.txt");
    log::debug!("{:?}", content);

However when running the code on the android emulator, I get a "No such file or directory" error.

Expected behavior

Hopefully I would get the content of the file when reading it :)

Screenshots

N/A

Environment:

The JAVA_HOME, ANDROID_HOME, and NDK_HOME environment variables are hopefully properly set.

Questionnaire

ealmloff commented 3 months ago

This is an area where integrating mobile tooling with dioxus would be very helpful (#2091). We currently add any assets you use with manganis or in the bundle.resources section to the list of assets to bundle on desktop, but we don't add them to the manifest cargo-mobile2 uses

It looks like the config in cargo mobile2 accepts an assets directory which may be helpful here.

We may also need to either add extra logic to read assets on android or use the existing WebViewBuilderExtAndroid trait in wry

Related issues: