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

Reduce --release apk and ipa sizes #16833

Closed
eseidelGoogle opened this issue Apr 21, 2018 · 30 comments
Closed

Reduce --release apk and ipa sizes #16833

eseidelGoogle opened this issue Apr 21, 2018 · 30 comments
Assignees
Labels
a: existing-apps Integration with existing apps via the add-to-app flow a: size Reducing IPA/APK/JS sizes c: performance Relates to speed or footprint issues (see "perf:" labels) engine flutter/engine repository. See also e: labels. perf: app size Performance issues related to app size (binary/code size) or disk space

Comments

@eseidelGoogle
Copy link
Contributor

We've had a bunch of issues related to this, most directly #12456 as another. Attempting to create an issue which we can drive to action.

Android Instant Apps #7614 will require a < 4MB initial .apk size (which doesn't have to include the Flutter engine perhaps, but should).

Our current "hello_world" apk size at time of writing is:
basic_material_app_android__compile release_size_bytes is 7907K
basic_material_app_ios__compile release_size_bytes is 9365K

My understanding is their is a ton of low hanging fruit here.

  • @mraleph has identified there is ~1mb of extra binary size in the dart runtime currently due to including observatory assets.
  • @chinmaygarde has previously stated that he believes there is about 1mb (compressed) of ICU data size to save with some compile flag changes.
  • It's possible we could even find a copy of ICU on Android or iOS which we could use directly (via GMSCore or other installed assets, we could even imagine having a fall-back path of locations to look). We investigated this in both Use system ICU on iOS #392 and Use system ICU on Android #394 but things may have changed.

I'm sure there is a ton more we could do here with some investigation. This was our 3rd most requested work area in our most recent user survey.

FYI @cbracken @Hixie

@eseidelGoogle eseidelGoogle added the engine flutter/engine repository. See also e: labels. label Apr 21, 2018
@Hixie Hixie added this to the bucket4 milestone Apr 22, 2018
@ohir
Copy link

ohir commented Apr 23, 2018

Support for Vector Graphics resources precompiled to some compact representation is crucial for the apk size, too. See #1831 discussion.

There are tools in AndroidStudio to convert .svg files to the xml based VectorDrawable.
This xml can be a source file compiled for more compact format, e.g. one sketched at
https://godoc.org/golang.org/x/exp/shiny/iconvg.

@dnfield
Copy link
Contributor

dnfield commented Apr 23, 2018

@ohir while asset compression/refactoring can certainly reduce APK/IPA size, I think this issue has more to do with "base" binary size for a bare minimum flutter app.

@mehmetf mehmetf added the a: existing-apps Integration with existing apps via the add-to-app flow label Apr 26, 2018
@chinmaygarde
Copy link
Member

Update: Was investigating this some more today. We only include observatory assets in the Debug and Profile runtime modes. However, vmservice sources are included in the release mode even though we will never initialize the same in that mode.

@mraleph
Copy link
Member

mraleph commented Apr 29, 2018

@chinmaygarde I am working on removing vmservice in release mode in dart-lang/sdk#32834

@saeid-ir
Copy link

saeid-ir commented May 7, 2018

Also mention that if you look at Storage usage of an app after installing the application in settings, its getting two or tree time more storage than the same app written in native.
I think its too heavy in comparison.

@rickyazhari
Copy link

Is there any way to reduce IPA size in release mode? I upload into appstore for testflight and got 32.8 MB for estimating appstore download size and 10 MB more bigger for app testflight. But i build release for APK android. it only got 15MB.

@eseidelGoogle
Copy link
Contributor Author

I believe the IPAs are built to include both 32-bit and 64-bit binaries, but the AppStore only sends part of the IPA down. @cbracken would know.

@cbracken
Copy link
Member

cbracken commented Jun 28, 2018

Correct; by default, we build universal binaries for iOS that include both armv7 and arm64 architectures for all three of:

  • Flutter.framework (the engine)
  • App.framework (the AOT-compiled app)
  • Runner (the entrypoint of the app)

Apple does app-thinning on their end such that the end-user downloads only the bits relevant to their device. To get the download size, log in to App Store Connect, select your app, navigate to the Activity page, select your build, then click the App Store File Sizes link.

@eseidelGoogle
Copy link
Contributor Author

We may want to add @cbracken's comment above to the FAQ: https://flutter.io/faq/#why-is-my-apk-or-ipa-so-big

@rickyazhari
Copy link

Thanks for feed back. Our apps actually has live right know in app store its called tanamduit financial platform for mutual fund. I do build with only single architecture(arm64) and seem success when export via adhoc just got ~12MB with single IPA. But when upload into app store still got a huge size( ~ 42 MB) looking forward into play store after figure out how to handle custom onBackPress when user hit the back button instead than hit button in app .

Keep up the good work. Still looking forward about my issue.

@nitinmehtaa
Copy link

My default flutter .apk file size is 90.40 MB, the one which shows increment counter. like how can we go ahead with this language for our production code? This is way to much than java or swift.

@jogboms
Copy link

jogboms commented Jul 28, 2018

@nitinmehtaa I believe that's for debug build, try building for release and watch the filesize change dramatically.

@zoechi zoechi added the a: size Reducing IPA/APK/JS sizes label Jul 29, 2018
@goderbauer
Copy link
Member

@nitinmehtaa Do a flutter build apk --release on your app and check the size of the produced APK.

@Hixie
Copy link
Contributor

Hixie commented Jul 30, 2018

@nitinmehtaa 90MB is definitely too big. If that was a release build, please file a bug and we'll help you look into it.

@nitinmehtaa
Copy link

@jogboms @goderbauer @Hixie Thanks a bunch, App size is ~29 MB now on release build but that is also way too high for my app. I've built simple UI using widgets. no Backend. Here is my project link : https://github.com/nitinmehtaa/e-commerce-suit-in-flutter
can anyone clone and check why this apk seems too heavy. It would be a great help and learning for me.

@zoechi
Copy link
Contributor

zoechi commented Aug 1, 2018

https://github.com/nitinmehtaa/e-commerce-suit-in-flutter/tree/master/build/app/outputs/apk/debug is in the debug folder which indicates it was created by a debug build. You need to measure the size of a release build as mentioned above.

@eseidelGoogle
Copy link
Contributor Author

flutter build apk should build you a release apk, which I would expect to be smaller. If you're still having issues, please file a separate bug and folks can help.

https://github.com/flutter/flutter/issues/16191 is a request about writing down some of our tips/tricks for understanding APK size. @goderbauer is actively working on reducing APK size as we speak.

@goderbauer
Copy link
Member

@nitinmehtaa Out of curiosity I took a look at your app. If I build it with the commands mentioned multiple times on this issues I get a final APK size of 7.5MB (this is on current master of flutter), which is about what I would have expected for the complexity of the app.

Not sure how you're arriving at your numbers?

~/dev $ git clone git@github.com:nitinmehtaa/e-commerce-suit-in-flutter.git
Cloning into 'e-commerce-suit-in-flutter'...
remote: Counting objects: 423, done.
remote: Compressing objects: 100% (253/253), done.
remote: Total 423 (delta 84), reused 415 (delta 80), pack-reused 0
Receiving objects: 100% (423/423), 87.21 MiB | 5.35 MiB/s, done.
Resolving deltas: 100% (84/84), done.
Checking out files: 100% (378/378), done.
~/dev $ cd e-commerce-suit-in-flutter/
~/dev/e-commerce-suit-in-flutter (master) $ flutter build apk --release
Running "flutter packages get" in e-commerce-suit-in-flutter...  9.4s
Initializing gradle...                                       1.4s
Resolving dependencies...                                   10.1s
Running 'gradlew assembleRelease'...                        34.8s
Built build/app/outputs/apk/release/app-release.apk (7.5MB).

@goderbauer
Copy link
Member

goderbauer commented Aug 2, 2018

To document some recent wins in the quest for smaller APK/IPA sizes:

Overall release APKs are now 2MB smaller with those improvements. This brings the release APK size of a minimal Flutter app down to 4.7MB (from previously 6.7MB).

Similar size reductions can also be seen on iOS for IPAs, but due to Apple's encryption and App Thinning process for IPAs uploaded to the App Store it's harder to document exact numbers.

Update Sept 28: App Store Connect reports for the iPhone X that these changes reduced release IPA download sizes by 3.8MB and the minimal Flutter app on iOS is now down to 12.6MB.

@aegis123
Copy link

aegis123 commented Aug 6, 2018

Can you also make use of the android bundle/apk split which makes separate APK's per supported CPU architecture? like an APK only for armv64 and an apk only for x86?

@goderbauer
Copy link
Member

@aegis123 Can you file a separate issue for that and cc me?

@matthew-carroll matthew-carroll moved this from To do to To do (Performance) in Add-to-App (stale) Aug 20, 2018
@matthew-carroll matthew-carroll moved this from To do (Performance) to In progress in Add-to-App (stale) Sep 13, 2018
@goderbauer
Copy link
Member

There have been some more wins:

tl;dr: Overall, on Android our APK size for a minimal Flutter app is now down to 4.48MB (minus 257KB compared to my comment from Aug 2). During the same time, our IPK download size on iOS for the minimal Flutter app has been reduced by 1.2MB and is now down to 11.4MB (as reported by App Store Connect for iPhone X).

@goderbauer
Copy link
Member

goderbauer commented Oct 3, 2018

Notes about the size difference between Android and iOS:

The majority of the size difference is coming from the second bullet point.

@goderbauer
Copy link
Member

Here's another update:

In total, the overall APK size of our famous minimal Flutter app is now down to 4.28 MB (minus 192KB compared to my last update). The IPA download size on iOS of the same app has been reduced by 0.6 MB and is now down to 10.8 MB (as reported by App Store Connect for iPhone X).

@goderbauer
Copy link
Member

The minimal Flutter app continues to shrink:

  • freetype2#a10b062 removed support for old/outdated font formats and other unused freetype2 modules
    • reduced libflutter.so by 135 KB (uncompressed)
    • reduced overall release APK size by 84 KB (compressed)

In total, the overall APK size of the minimal Flutter app is now down to 4.20 MB (minus 84 KB compared to my last update). The IPA download size has not changed since the last update.

@eseidelGoogle
Copy link
Contributor Author

My understanding is that we've gotten most of the meat we're going to get here w/o more radical changes. Is my understanding correct? If so, is there still value in keeping this bug open @goderbauer?

@goderbauer
Copy link
Member

Your understanding is correct. My plan is to do one last update on this bug with the latest numbers and then close it.

@goderbauer
Copy link
Member

goderbauer commented Dec 13, 2018

Some additional changes have landed that shrunk our minimal Flutter app further:

All in all, the download size of the minimal Flutter app APK as reported by apkanalyzer from the Android SDK is now down to 4.06 MB. IPA download size as reported by Apple's App Store Connect for an iPhone X remains at 10.8 MB.

With that, I am now going to close this issue. We've pretty much removed all cruft from a Flutter APK/IPA at this point. Reducing the size further would require more radical changes that we should track in separate issues.

Thanks for following along!

Add-to-App (stale) automation moved this from In progress to Done Dec 13, 2018
@csedeepakyadav
Copy link

I would recommend splitting apk to get the best possible reduced app size

my initial apk size was 9.8mb :-

Built build\app\outputs\apk\release\app-release.apk (9.8MB).

After Splitting:-

Built build\app\outputs\apk\release\app-armeabi-v7a-release.apk (4.9MB).
Built build\app\outputs\apk\release\app-arm64-v8a-release.apk (5.2MB).

To split the APKs per ABI, run:

flutter build apk --target-platform android-arm,android-arm64 --split-per-abi
Learn more on: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split

@liyuqian liyuqian added the perf: app size Performance issues related to app size (binary/code size) or disk space label Mar 8, 2020
@liyuqian liyuqian added the c: performance Relates to speed or footprint issues (see "perf:" labels) label Mar 30, 2020
@lock
Copy link

lock bot commented Apr 15, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@lock lock bot locked and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: existing-apps Integration with existing apps via the add-to-app flow a: size Reducing IPA/APK/JS sizes c: performance Relates to speed or footprint issues (see "perf:" labels) engine flutter/engine repository. See also e: labels. perf: app size Performance issues related to app size (binary/code size) or disk space
Projects
No open projects
Development

No branches or pull requests