Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed assets in Android APKs #82

Closed
MarijnS95 opened this issue Nov 30, 2022 · 10 comments · Fixed by #122
Closed

Embed assets in Android APKs #82

MarijnS95 opened this issue Nov 30, 2022 · 10 comments · Fixed by #122
Assignees

Comments

@MarijnS95
Copy link
Member

Before diving into the implementation for this, what's the best way to embed assets on Android nowadays?

  1. We can pack them up in the .apk and read (or map if packed uncompressed) them at runtime using AAsset;
  2. Use OBB files;
  3. Something with app bundles they have a similar concept to "OBB extension files" named "asset packs" or "Play Asset Delivery" to separate (cross-platform) data from per-platform code.

@dvc94ch Does xbuild support anything for this nowadays, and if not, what do you reckon is the best way forward?

@dvc94ch
Copy link
Contributor

dvc94ch commented Nov 30, 2022

flutter uses option 1. but open to suggestions. I don't have a strong opinion, but will probably need to look into this problem soon for my own app

@MarijnS95
Copy link
Member Author

I'd be fine to do 1. since that's nice-to-have anyway for smaller assets and quick solutions, before diving into the crevices of app bundles. OBB seems to be deprecated, better not spend time on that.

@dvc94ch
Copy link
Contributor

dvc94ch commented Dec 9, 2022

I think there are two valid ways of doing this. You embed all assets in the binary using include_dir! (what I'm currently doing) or integrate with platform specific packaging. Would like to see a crate for that with some support in xbuild if needed, but probably won't be tackling this myself.

See how to handle this on macos here [0] with ios likely being very similar.

@dvc94ch
Copy link
Contributor

dvc94ch commented Jan 21, 2023

closing this for now as out of scope

@dvc94ch dvc94ch closed this as completed Jan 21, 2023
@MarijnS95 MarijnS95 reopened this Jan 21, 2023
@MarijnS95
Copy link
Member Author

Using it for my own tracking purposes.

@NiklasEi
Copy link

Are there any news on this?
I am trying to move my bevy app from cargo-apk to xbuild to get support for building app bundles. The app builds and opens up, but the apk does not contain the assets. cargo apk puts them in the apk based on the path provided in the Cargo.toml. I guess that's option 1?

@MarijnS95
Copy link
Member Author

@NiklasEi I'm still using my assets branch on a daily basis (seems I forgot to link that here) and am eyeing a PR sooner rather than later, after improving compression support.

This is only option 1. though; separately I dearly wish to add native .aab support but that's further down the pipeline. Note that xbuild doesn't yet support that, except when using the gradle backend (otherwise it (used to?) generate .aab files which were just APKs).

@NiklasEi
Copy link

NiklasEi commented Jul 17, 2023

I'm still using my assets branch on a daily basis (seems I forgot to link that here) and am eyeing a PR sooner rather than later, after improving compression support.

Awesome, just what I needed! I went ahead and added support for globs in asset paths: MarijnS95#1
Now my bevy app runs fine with

  assets: 
    - "../assets/*"

@jkelleyrtp
Copy link

Hi, I'm trying to add support to manganis (dioxus' new linker-based asset solution)

One of the things we need to do is dynamically canonicalize the assets per-platform. I'm trying to get that working with xbuild.

I see #122 but no examples on reading from that directory. Is it just std::fs::read("assets/blah.txt")?

@MarijnS95
Copy link
Member Author

@jkelleyrtp that's about what zip.add_file() is supposed to do, based on the difference between the asset variable and the file_name. add_directory() does this recursively.

As documented, only the file_name() (the last component of the given path) is put in the APK. So specifying an asset foo/bar/blah.txt gives you assets/blah.txt in the APK (and foo gives you assets/foo/bar/blah.txt together with any other files inside foo/). If you need anything else, right now the only option is to build a directory tree on the file system (maybe with symlinks?).

if you need anything more sophisticated (i.e. an optional target: parameter) in manifest.yaml, feel free to contribute :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants