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

Space drawback of this stack #51

Open
tkkcc opened this issue Dec 21, 2022 · 3 comments
Open

Space drawback of this stack #51

tkkcc opened this issue Dec 21, 2022 · 3 comments

Comments

@tkkcc
Copy link

tkkcc commented Dec 21, 2022

I build a release apk of agdk-eframe with space optimized profile, it's 27M. Without egui_demo_lib, it's 23M. Without jniLibs, it's 5.2M. The drawback of this stack is rust codes are compiled to all targets and bundled to apk(if distributed as a single apk, not via app store). Any tips for slim apk?

# use release-space-optimized profile in https://github.com/bbqsrc/cargo-ndk/blob/main/example/Cargo.toml
cargo ndk -t armeabi-v7a -t arm64-v8a -t x86 -t x86_64 \
-o app/src/main/jniLibs/ build --profile release-space-optimized
./gradlew assembleRelease

# check size
find app/src/main/jniLibs/ -type f -exec du -ah {} +
5.9M	app/src/main/jniLibs/x86/libmain.so
5.3M	app/src/main/jniLibs/arm64-v8a/libmain.so
4.2M	app/src/main/jniLibs/armeabi-v7a/libmain.so
5.9M	app/src/main/jniLibs/x86_64/libmain.so
find app/build/outputs/apk -type f -exec du -ah {} +
27M	app/build/outputs/apk/release/app-release-unsigned.apk
4.0K	app/build/outputs/apk/release/output-metadata.json

# remove egui_demo_lib dependency, check size
find app/src/main/jniLibs/ -type f -exec du -ah {} +
4.7M	app/src/main/jniLibs/x86/libmain.so
4.3M	app/src/main/jniLibs/arm64-v8a/libmain.so
3.3M	app/src/main/jniLibs/armeabi-v7a/libmain.so
4.8M	app/src/main/jniLibs/x86_64/libmain.so
find app/build/outputs/apk -type f -exec du -ah {} +
23M	app/build/outputs/apk/release/app-release-unsigned.apk
4.0K	app/build/outputs/apk/release/output-metadata.json
@rib
Copy link
Collaborator

rib commented Dec 21, 2022

Interesting. Can you try with lto enabled too? I guess the generated ndk-sys crate bindings may be quite large and enabling link time optimizations could help remove unused code.

Are there any existing tools that can graph the relationship between the total size and the input crates that can give some more insight here (I'd guess there are but haven't looked at this for a while)

@rib
Copy link
Collaborator

rib commented Dec 21, 2022

Oh, the apk presumably also supports multiple architectures too. The libmain.so for each architecture is less than 5Mb.

You could perhaps reduce the number of architectures you need to support?

@rib
Copy link
Collaborator

rib commented Dec 21, 2022

Just checking the Cargo.toml that you linked from https://github.com/bbqsrc/cargo-ndk/blob/main/example/Cargo.toml I see that the release-space-optimized profile already enables lto=true

Under 5Mb for the binary doesn't seem that alarming to me.

In terms of distribution then maybe you can look at removing some of the targets if you want to minimized the size of a single apk.

Maybe also check some of the general advice here in case it's helpful: https://developer.android.com/topic/performance/reduce-apk-size

If you e.g plan to distribute something via the Play Store then it looks like the best thing to do there is make sure to build with an app bundle: https://developer.android.com/guide/app-bundle and let Google build your final apks that will be optimized for each individual target that may download from the Play Store.

I've not tried building an app bundle with the android-activity examples such as agdk-eframe but you can find some guidance about how Gradle can be used to build an app bundle here: https://developer.android.com/studio/build/building-cmdline#build_bundle and hopefully that will automatically work with the examples too.

Btw just as a heads up to let you know. I'm planning on moving all the examples in this repo into a standalone repo here: https://github.com/rust-mobile/rust-android-examples

see: #50

(just so hopefully you don't get surprised if you see the examples disappear from here soon)

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

No branches or pull requests

2 participants