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

Realm binary files take a lot of space in apk file, and include binary files for non-target platform. #1670

Closed
zhxst opened this issue May 7, 2024 · 8 comments · Fixed by #1682

Comments

@zhxst
Copy link

zhxst commented May 7, 2024

What happened?

My previous Flutter app takes about 63 MB in apk release build.
After import Realm, the apk file size become 131 MB, which is double from before.

By unpack the release package. It turns out that Realm include binary files for all the target platform.
By default, flutter only build for android-arm, android-arm64 and android-x64. But realm also include android-x86 binary files. Which takes 18.6MB extra space.

Here is another example , which only target android-arm64 when build:
image

So please make realm package follow the flutter --target-platform, this will save a lot of space for release build apks.

Thank you.

Repro steps

  1. Use any Flutter project which import realm.
  2. Build android apk, use --target-platform or --split-per-abi.
  3. Unpack the generate apks. Check the realm binary files inside apk.

Version

3.19.5

What Atlas Services are you using?

Local Database only

What type of application is this?

Flutter Application

Client OS and version

macOS 13.6

Code snippets

No response

Stacktrace of the exception/crash you're getting

No response

Relevant log output

No response

Copy link

sync-by-unito bot commented May 7, 2024

➤ PM Bot commented:

Jira ticket: RDART-1022

@nirinchev
Copy link
Member

@nielsenko do you know if Google Play repackages flutter apps to remove binaries for architectures that don't match the install device? I remember this used to work for .NET apps but I'm not sure if there's anything in Flutter that would prevent this mechanism from working.

@nielsenko
Copy link
Contributor

nielsenko commented May 22, 2024

I'm not sure where you get the 161MB from. If I do flutter build apk on a basic project using realm, I get an apk size of 36.8MB.

flutter build apk

Directory: '/Users/kasper/.puro/shared/pub_cache/hosted/pub.dev/realm-2.2.1/android/src/main/cpp/lib'
Realm binaries for 2.2.1 already downloaded
Realm install command finished.
Running Gradle task 'assembleRelease'...                            5.6s
✓ Built build/app/outputs/flutter-apk/app-release.apk (36.8MB)

If I use flutter build apk --split-per-abi I get:

flutter build apk --split-per-abi

Directory: '/Users/kasper/.puro/shared/pub_cache/hosted/pub.dev/realm-2.2.1/android/src/main/cpp/lib'
Realm binaries for 2.2.1 already downloaded
Realm install command finished.
Running Gradle task 'assembleRelease'...                            7.8s
✓ Built build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk (9.8MB)
✓ Built build/app/outputs/flutter-apk/app-arm64-v8a-release.apk (11.7MB)
✓ Built build/app/outputs/flutter-apk/app-x86_64-release.apk (11.6MB)

So less than 12MB in all cases, which includes not just realm, but flutter as well.

However. In general you should avoid using apks and instead build an app bundle by invoking flutter build appbundle. If you upload a full bundle to Google Play it should split correctly, and your users should only download for the target platform.
The only reason to use apks is if you distribute your app by some other mean that doesn't support Android app bundles.

When I do that I get:

flutter build appbundle

Directory: '/Users/kasper/.puro/shared/pub_cache/hosted/pub.dev/realm-2.2.1/android/src/main/cpp/lib'
Realm binaries for 2.2.1 already downloaded
Realm install command finished.
Running Gradle task 'bundleRelease'...                              8.5s
✓ Built build/app/outputs/bundle/release/app-release.aab (36.9MB)

but notice that the play store will split this up for you, before the user download the app

@zhxst Have you tried opening a bundle retrieved from Google play?

@nielsenko
Copy link
Contributor

nielsenko commented May 22, 2024

But this made me notice that we build for x86 as well as x86_64, arm64-v8a, and armabi-v7a which makes no sense, since flutter doesn't support it.

@zhxst
Copy link
Author

zhxst commented May 22, 2024

I know that Play Store will generate smaller apk.
But some time I have to send universal apk file to my colleague or customer for test.
So --split-per-abi works correct but --target-platform not I guess.
I will try to use --split-per-abi as workaround.

@nielsenko
Copy link
Contributor

@zhxst --split-per-abi is not a work-around. If you insist on creating apks, then that is the recommended approach. See https://docs.flutter.dev/deployment/android#build-an-apk.

@nielsenko
Copy link
Contributor

nielsenko commented May 22, 2024

... But some time I have to send universal apk file to my colleague or customer for test.

@zhxst If you insist on sending a fat-apk then yes an app using realm will currently be 36.8MB+, but that includes flutter itself.

But I'm dropping the x86 slice in #1682, so that should strip it down a bit (to ~30MB).

@zhxst
Copy link
Author

zhxst commented May 22, 2024

@nielsenko Thank you for your response. --split-per-abi is a good idea. Remove the x86 slice also helps.
I guess it's a bug of --split-per-abi from Flutter side. Because I found another plugin also have this issue.
Maybe I will file an issue to the flutter team.

@zhxst zhxst closed this as completed May 22, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants