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

Open
eseidelGoogle opened this Issue Apr 21, 2018 · 23 comments

Comments

@eseidelGoogle
Contributor

eseidelGoogle commented Apr 21, 2018

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 #392 and #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

@Hixie Hixie added this to the bucket4 milestone Apr 22, 2018

@ohir

This comment has been minimized.

Show comment
Hide comment
@ohir

ohir 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.

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

This comment has been minimized.

Show comment
Hide comment
@dnfield

dnfield Apr 23, 2018

Member

@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.

Member

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.

@chinmaygarde

This comment has been minimized.

Show comment
Hide comment
@chinmaygarde

chinmaygarde Apr 28, 2018

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.

Member

chinmaygarde commented Apr 28, 2018

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

This comment has been minimized.

Show comment
Hide comment
@mraleph

mraleph Apr 29, 2018

Contributor

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

Contributor

mraleph commented Apr 29, 2018

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

@saeidakbari

This comment has been minimized.

Show comment
Hide comment
@saeidakbari

saeidakbari 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.

saeidakbari 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

This comment has been minimized.

Show comment
Hide comment
@rickyazhari

rickyazhari Jun 28, 2018

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.

rickyazhari commented Jun 28, 2018

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

This comment has been minimized.

Show comment
Hide comment
@eseidelGoogle

eseidelGoogle Jun 28, 2018

Contributor

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.

Contributor

eseidelGoogle commented Jun 28, 2018

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

This comment has been minimized.

Show comment
Hide comment
@cbracken

cbracken Jun 28, 2018

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@eseidelGoogle

eseidelGoogle Jun 28, 2018

Contributor

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

Contributor

eseidelGoogle commented Jun 28, 2018

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

This comment has been minimized.

Show comment
Hide comment
@rickyazhari

rickyazhari Jul 6, 2018

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.

rickyazhari commented Jul 6, 2018

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

This comment has been minimized.

Show comment
Hide comment
@nitinmehtaa

nitinmehtaa Jul 28, 2018

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.

nitinmehtaa commented Jul 28, 2018

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

This comment has been minimized.

Show comment
Hide comment
@jogboms

jogboms Jul 28, 2018

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

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 label Jul 29, 2018

@goderbauer

This comment has been minimized.

Show comment
Hide comment
@goderbauer

goderbauer Jul 30, 2018

Member

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

Member

goderbauer commented Jul 30, 2018

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

@Hixie

This comment has been minimized.

Show comment
Hide comment
@Hixie

Hixie Jul 30, 2018

Contributor

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

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

This comment has been minimized.

Show comment
Hide comment
@nitinmehtaa

nitinmehtaa Aug 1, 2018

@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.

nitinmehtaa commented Aug 1, 2018

@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

This comment has been minimized.

Show comment
Hide comment
@zoechi

zoechi Aug 1, 2018

Contributor

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.

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

This comment has been minimized.

Show comment
Hide comment
@eseidelGoogle

eseidelGoogle Aug 1, 2018

Contributor

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.

#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.

Contributor

eseidelGoogle commented Aug 1, 2018

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.

#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

This comment has been minimized.

Show comment
Hide comment
@goderbauer

goderbauer Aug 1, 2018

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).
Member

goderbauer commented Aug 1, 2018

@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

This comment has been minimized.

Show comment
Hide comment
@goderbauer

goderbauer Aug 2, 2018

Member

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

  • flutter/engine#5784 removed Dart's VM Service from the compiled Dart code in release mode:
    • reduced dart code snapshots (contains framework + app code) on Android by 1.5MB (uncompressed)
    • reduced overall release APK size by 475KB (compressed)
  • flutter/engine#5922 switched Flutter to a new minimal ICU data config:
    • reduced size of ICU data bundled with APKs/IPAs by 5.1MB (uncompressed)
    • reduced overall release APK size by 1.6MB (compressed)

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.

Member

goderbauer commented Aug 2, 2018

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

  • flutter/engine#5784 removed Dart's VM Service from the compiled Dart code in release mode:
    • reduced dart code snapshots (contains framework + app code) on Android by 1.5MB (uncompressed)
    • reduced overall release APK size by 475KB (compressed)
  • flutter/engine#5922 switched Flutter to a new minimal ICU data config:
    • reduced size of ICU data bundled with APKs/IPAs by 5.1MB (uncompressed)
    • reduced overall release APK size by 1.6MB (compressed)

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

This comment has been minimized.

Show comment
Hide comment
@aegis123

aegis123 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?

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

This comment has been minimized.

Show comment
Hide comment
@goderbauer

goderbauer Aug 13, 2018

Member

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

Member

goderbauer commented Aug 13, 2018

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

@matthew-carroll matthew-carroll added this to To do in Add2App Aug 20, 2018

@matthew-carroll matthew-carroll moved this from To do to To do (Performance) in Add2App Aug 20, 2018

@matthew-carroll matthew-carroll moved this from To do (Performance) to In progress in Add2App Sep 13, 2018

@goderbauer

This comment has been minimized.

Show comment
Hide comment
@goderbauer

goderbauer Oct 3, 2018

Member

There have been some more wins:

  • flutter/engine#6097 switches flutter to an even smaller ICU data config:
    • reduced size of ICU data bundled with APKs/IPAs by 363KB (uncompressed)
    • reduced overall release APK size by 84KB (compressed), similar reduction on iOS
  • flutter/buildroot#167 fixed symbol visibility and flutter/buildroot#165 tweaked compiler flags for Android:
    • reduced libflutter.so by 499KB (uncompressed)
    • reduced overall release APK size by 263KB (compressed)
  • flutter/engine#6247 is stripping debug symbols from Flutter.framework:
    • reduced Flutter.framework by 3.8MB (uncompressed)
    • reduced overall release IPA download size by 0.7 MB (as reported by App Store Connect for iPhone X)
    • reduced overall release IPA install size by 4MB (as reported by App Store Connect for iPhone X)
  • flutter/engine#6337 fixes symbol visibility of Dart on iOS:
    • reduced Flutter.framework by 145KB (uncompressed)
  • #22245 is stripping debug symbols from App.framework:
    • reduces App.framework by ~23% (uncompressed), that's minus 1.6MB for the minimal flutter app or minus 6MB for Flutter Gallery (uncompressed)
    • reduced release IPA download size of minimal Flutter app by 0.1MB on iPhone X as per App Store Connect
    • reduced release IPA install size of minimal Flutter app by 0.9MB on iPhone X as per App Store Connect

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).

Member

goderbauer commented Oct 3, 2018

There have been some more wins:

  • flutter/engine#6097 switches flutter to an even smaller ICU data config:
    • reduced size of ICU data bundled with APKs/IPAs by 363KB (uncompressed)
    • reduced overall release APK size by 84KB (compressed), similar reduction on iOS
  • flutter/buildroot#167 fixed symbol visibility and flutter/buildroot#165 tweaked compiler flags for Android:
    • reduced libflutter.so by 499KB (uncompressed)
    • reduced overall release APK size by 263KB (compressed)
  • flutter/engine#6247 is stripping debug symbols from Flutter.framework:
    • reduced Flutter.framework by 3.8MB (uncompressed)
    • reduced overall release IPA download size by 0.7 MB (as reported by App Store Connect for iPhone X)
    • reduced overall release IPA install size by 4MB (as reported by App Store Connect for iPhone X)
  • flutter/engine#6337 fixes symbol visibility of Dart on iOS:
    • reduced Flutter.framework by 145KB (uncompressed)
  • #22245 is stripping debug symbols from App.framework:
    • reduces App.framework by ~23% (uncompressed), that's minus 1.6MB for the minimal flutter app or minus 6MB for Flutter Gallery (uncompressed)
    • reduced release IPA download size of minimal Flutter app by 0.1MB on iPhone X as per App Store Connect
    • reduced release IPA install size of minimal Flutter app by 0.9MB on iPhone X as per App Store Connect

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

This comment has been minimized.

Show comment
Hide comment
@goderbauer

goderbauer Oct 3, 2018

Member

Notes about the size difference between Android and iOS:

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment