rive-app / rive-flutter

Flutter runtime for Rive
https://rive.app
MIT License
1.21k stars 191 forks source link

APK size has massively grown when upgrading from 0.9.1 to 0.10.x #274

Open mark8044 opened 1 year ago

mark8044 commented 1 year ago

My App APK hovers around 70MB on 0.9.1. With the only change being a move to 0.10.0, the APK size grows to 185MB

ttb-inc commented 1 year ago

I have the same issue. .apk, .aab file size doubled.

mickyliu945 commented 1 year ago

Same question. Is there any solution?

luigi-rosso commented 1 year ago

0.10.0 adds some groundwork for the upcoming text feature. It should add ~450KB. Sounds like we have a configuration bug. We'll take a look. For now use 0.9.1.

Can anyone confirm if that's the size of the final stripped store APK? The included binaries will definitely need to be compiled for each target arch so a fat binary will be generated that should be stripped, but 70MB sounds far too big.

mark8044 commented 1 year ago

0.10.0 adds some groundwork for the upcoming text feature. It should add ~450KB. Sounds like we have a configuration bug. We'll take a look. For now use 0.9.1.

Can anyone confirm if that's the size of the final stripped store APK? The included binaries will definitely need to be compiled for each target arch so a fat binary will be generated that should be stripped, but 70MB sounds far too big.

Mine is 70MB on my disk and 34MB when in the Play Store. That's with 0.9.1. Have not attempted to put the 0.10.0 version onto the store out of fear when I saw the 185MB on my disk

luigi-rosso commented 1 year ago

I ran flutter build apk for our example app and I see the following sizes:

Version Size
0.9.1 18.1MB
0.10.0 21.4MB

~3.3MB bigger, which is definitely more but nowhere near the increase you're seeing. Our native library is about 450KB but we also now depend on ffi and plugin_platform_interface which definitely add some of their own size too.

What build command are you using?

mark8044 commented 1 year ago

I ran flutter build apk for our example app and I see the following sizes:

Version Size 0.9.1 18.1MB 0.10.0 21.4MB ~3.3MB bigger, which is definitely more but nowhere near the increase you're seeing. Our native library is about 450KB but we also now depend on ffi and plugin_platform_interface which definitely add some of their own size too.

What build command are you using?

flutter build apk

the difference is for sure coming from rive 0.10.0

Literally running the build back to back and only changing pubspec.yaml for different version of rive results in the massive size difference in APK

I did it just now again: 0.9.1 ==>

Running Gradle task 'assembleRelease'...                          227.6s 
✓  Built build/app/outputs/flutter-apk/app-release.apk (72.8MB).

0.10.0 ==>

Running Gradle task 'assembleRelease'...                          386.9s 
✓  Built build/app/outputs/flutter-apk/app-release.apk (190.2MB).

0.9.1 (back down again) ==>

Running Gradle task 'assembleRelease'...                          148.4s 
✓  Built build/app/outputs/flutter-apk/app-release.apk (72.8MB).

On a related / unrelated note, when building with 0.10.0 I do also get this message, although build otherwise progresses normally:

One or more plugins require a higher Android NDK version.
Fix this issue by adding the following to /android/app/build.gradle:
android {
  ndkVersion 25.1.8937393
  ...
}
mjtalbot commented 1 year ago

this is interesting! taking a look at the apk built from the example app locally in android studio shows that the additional ~3.3MB we see seem to come from 4 versions of the librive_text.so.

image

I would be very curious to be able to take a look at the contents of your apk's to see where the additional size is coming from, that might show us where we need to look here.

if you do not mind sharing them, sharing them with support@rive.app would be very helpful, (or over discord), but at this point even just a screenshot might be enough to point us in the right direction.

also, is it possible to try updating your ndk version?

mark8044 commented 1 year ago

this is interesting! taking a look at the apk built from the example app locally in android studio shows that the additional ~3.3MB we see seem to come from 4 versions of the librive_text.so. image

I would be very curious to be able to take a look at the contents of your apk's to see where the additional size is coming from, that might show us where we need to look here.

if you do not mind sharing them, sharing them with support@rive.app would be very helpful, (or over discord), but at this point even just a screenshot might be enough to point us in the right direction.

also, is it possible to try updating your ndk version?

Ok I have taken screen shots of the two, hopefully this helps

0.9.1 Screen Shot 2023-01-06 at 6 45 28 AM

0.10.0 Screen Shot 2023-01-06 at 6 50 15 AM

As for the ndk, that is a whole other can of worms. For some reason it does not want to accept that I have the latest ndk at that level already installed. Id rather not hardcode that version in, so I still have to work on that "issue"

mickyliu945 commented 1 year ago
rive

^0.10.0

tarek360 commented 1 year ago

For me, my fat APK size is decreased from 55MB to 17MB when I downgraded from rive 0.10.0 to rive 0.9.1

mjtalbot commented 1 year ago

Something is clearly wrong, we have not been able to reproduce the bloated application size with our sample application, but there must be something else at play here that we are missing.

It also seems that our "raw size" is significantly different to in our sample app for the flutter.so as well, even though the download size is comparable there

Do any of you mind sharing access your source code with our team, I think that might help us find the issue faster as we will hopefully be able to reproduce the size bloating issue then. If this is an option, please reach out to us on support@rive.app or on discord (I'm Max @ Rive)

tarek360 commented 1 year ago

@mjtalbot Actually, I can reproduce the issue with the rive example app, it's ~35MB difference in the example app between 0.9.1 and 0.10.0

FYI, I'm on on the latest Flutter version, are you?

mjtalbot commented 1 year ago

Ofcourse, this is sounds promising... on flutter --version Flutter 3.7.0-15.0.pre... which version are you on? going to try this with stable and see what results I get

mjtalbot commented 1 year ago

I've just built a the example app in a clean checkout of the https://github.com/rive-app/rive-flutter repository using flutter channel beta & flutter channel stable and I am not able to reproduce the issue you are seeing

Might there be another difference? I'm running on an intel mac running macOS Ventura 13.2 (a) Beta (22D7750270d)

image

(also just ran master branch which also gets to about 21.9 MB for me)

mjtalbot commented 1 year ago

I've also just gotten my windows machine building this, it also gets to 21.5MB (its running on the flutter stable channel, 3.3.10)

tarek360 commented 1 year ago

Ofcourse, this is sounds promising... on flutter --version Flutter 3.7.0-15.0.pre... which version are you on? going to try this with stable and see what results I get

I'm on Flutter 3.3.10 • channel stable

also I can reproduce the issue on Codemagic CI, let me try to make it public and share it with you.

tarek360 commented 1 year ago

@mjtalbot I have messaged you on Discord.

mark8044 commented 1 year ago

Mine were also on 3.3.10 stable

luigi-rosso commented 1 year ago

Could one of you that's getting a large apk send me the .aar generated (after running flutter build apk) in the build/rive_common/outputs/aar folder? You can either attach it here (rename to .zip might work) or email luigi@rive.app.

Mine looks like this for the example app:

CleanShot 2023-01-13 at 11 16 21@2x
luigi-rosso commented 1 year ago

I grabbed one from the codemagic CI someone shared. These are larger but not as bad as some of the ones posted here.

I suspect this must boil down to Android SDK differences and compilers used. Could @mark8044 @mickyliu945 or anyone getting the huge APKs share their Flutter Doctor output? The android SDK for my Flutter setup is 33.0.0:

Android toolchain - develop for Android devices (Android SDK version 33.0.0)
mark8044 commented 1 year ago

I grabbed one from the codemagic CI someone shared. These are larger but not as bad as some of the ones posted here.

I suspect this must boil down to Android SDK differences and compilers used. Could @mark8044 @mickyliu945 or anyone getting the huge APKs share their Flutter Doctor output? The android SDK for my Flutter setup is 33.0.0:

Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Flutter (Channel stable, 3.3.10, on macOS 12.6 21G115 darwin-x64, locale en-US)
    • Flutter version 3.3.10 on channel stable at /Users/xx/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 135454af32 (4 weeks ago), 2022-12-15 07:36:55 -0800
    • Engine revision 3316dd8728
    • Dart version 2.18.6
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/xx/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.2

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] Connected device (2 available)

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
tarek360 commented 1 year ago

I grabbed one from the codemagic CI someone shared. These are larger but not as bad as some of the ones posted here.

I suspect this must boil down to Android SDK differences and compilers used. Could @mark8044 @mickyliu945 or anyone getting the huge APKs share their Flutter Doctor output? The android SDK for my Flutter setup is 33.0.0:

Android toolchain - develop for Android devices (Android SDK version 33.0.0)

@luigi-rosso I have shared my Codemagic CI build with @mjtalbot

My android SDK is 33.0.1

flutter doctor -v                                                                                              
[✓] Flutter (Channel stable, 3.3.10, on macOS 12.5 21G72 darwin-arm, locale en-US)
    • Flutter version 3.3.10 on channel stable at xx
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 135454af32 (4 weeks ago), 2022-12-15 07:36:55 -0800
    • Engine revision 3316dd8728
    • Dart version 2.18.6
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at xx
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] IntelliJ IDEA Community Edition (version 2022.2.3)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 71.2.5
    • Dart plugin version 222.4345.14

[✓] VS Code (version 1.74.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 12.5 21G72 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 109.0.5414.87

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
mickyliu945 commented 1 year ago

The librive_text.so decrease to 2.1M, upgrade ndk to "25.1.8937393"

mjtalbot commented 1 year ago

thank you @tarek360 for the codemagic repro, I've forked your sample & created a codemagic pipeline to repro the issue & I can confirm that updating the NDK fixes the bulk of the size increase, and brings us back to what we are seeing when building our sample project.

& @mickyliu945 I am also able to confirm that upgrading the ndk resolves this size issue. even though I am seeing a smaller librive_text.so size, can you share what the analyze screenshot looks like for yours?

I've forked your sample to https://github.com/mjtalbot/rive-demo, and started building releases on codemagic, the latest (with the fixed sizes is available here https://codemagic.io/app/63c535de9e9846469ee7d5a2/build/63c544b9e94b05b3719f3a5f)

building against 0.9.1 results in 18M 16 Jan 11:55 app-release.code.0.9.x.apk building against 0.10.1 results in 51M 16 Jan 12:11 app-release.code.0.10.x.apk

updating the build.gradle https://github.com/mjtalbot/rive-demo/blob/main/android/app/build.gradle to include ndkVersion 25.1.8937393 results in 21M 16 Jan 12:34 app-release.code25.0.10.x.apk

this brings the librive_text.so size to 700-900kb per platform

image
HayesGordon commented 1 year ago

This may not be related, but could be part of the issue for some of you.

See the hot fixes for the latest Flutter 3.7.3 - https://github.com/flutter/flutter/wiki/Hotfixes-to-the-Stable-Channel

In particular: Asset inclusion regression can cause unexpected app bundle size increase

mark8044 commented 1 year ago

This may not be related, but could be part of the issue for some of you.

See the hot fixes for the latest Flutter 3.7.3 - https://github.com/flutter/flutter/wiki/Hotfixes-to-the-Stable-Channel

In particular: Asset inclusion regression can cause unexpected app bundle size increase

Unfortunately, still massive APK size with Flutter 3.7.3.

Devs are saying the fix is to set a higher NDK version, but would prefer not to hardcode one in

remonh87 commented 1 year ago

When integrating Rive in our CI I noticed a huge spike in build times. It turned out that it exceeded the cache limit of our service provider. I dived a bit more into it and noticed Rive's size in pub cache is huge. Is there a reason why this is so huge and how to optimize the size?

Now Rive alone exceeds the cache limits of CI providers and dramatically slowing down our build times. When downgrading to v0.9.1 it is way less.

220968882-bdcbdbe3-1ac8-4bd9-98c6-a33df7e970db

mjtalbot commented 1 year ago

@millerovv & @remonh87, which ndk version are you targeting? & do you get a warning like the following when you build? (if you have a flutter doctor output that would be helpful)

One or more plugins require a higher Android NDK version.
Fix this issue by adding the following to /android/app/build.gradle:
android {
  ndkVersion 25.1.8937393
  ...
}

That being said I can reproduce the bloated cache size, so taking a look at what is causing this, but it looks like a separate issue to this, so i've filed a ticket for that here

millerovv commented 1 year ago

which ndk version are you targeting?

@mjtalbot I also used the same ndkVersion "25.1.8937393" in gradle.build.

All in all this issue is less critical for our project, compared to 291, since for us size increase is not that "massive", but of course it's still there.

remonh87 commented 1 year ago

@mjtalbot I can confirm I use the idk mentioned. I agree with splitting the issue 👍

A7mdlbanna commented 1 year ago

I don't even use Rive, but for some reason, it appeared in my APK! I tried flutter pub add rive then flutter pub remove rive, and nothing new.

changing the ndk version to 25.1.8937393 resolved this issue though :)

rohanjsh commented 1 year ago

Similar Problem, huge difference identified.

Top one is built with the latest rive version - v0.11.4 Bottom one is built with - v0.9.1

(note: tree shaking is for both the builds, and built with exact same commands)

screenshot_2023-07-06_at_14 58 48_720

berkekbgz commented 1 year ago

Same here:

> flutter --version
Flutter 3.13.0-0.2.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision ac71592bc6 (3 weeks ago) • 2023-07-18 14:53:57 -0600
Engine • revision e14db68a86
Tools • Dart 3.1.0 (build 3.1.0-262.2.beta) • DevTools 2.25.0
> rive: 0.11.14
> rive_common: 0.2.6

DIFF:

image

ABDERRAHMANE-OUALI commented 10 months ago

The added Text support for rive is clearlly what caused the increase in the bundle of rive package between 0.9.1 and 0.10.0

Text features should be optional and opt-in only when needed maybe as a standalone package or module

echogit commented 5 months ago

I have the same issue here, from 62MB without any rive to 112MB with a little test animation (animation itself 16k)

[√] Flutter (Channel stable, 3.19.6, on Microsoft Windows [versÆo 10.0.19045.4291], locale pt-BR)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)

Below is the apk size: rive-libs-size

I also have this ndk message issue:

One or more plugins require a higher Android NDK version.
Fix this issue by adding the following to C:\Users\echof\StudioProjects\speakout\android\app\build.gradle:
android {
  ndkVersion "25.1.8937393"
}

On android studio the ndkVersion "25.1.8937393" version is already selected.

And I already have the following to build.gradle: ndkVersion "25.1.8937393"

echogit commented 5 months ago

I found the solution, on my build.gradle I had already a "ndkVersion flutter.ndkVersion", which I didn't comment:

android {
    ndkVersion "25.1.8937393"
    namespace "com.speakout.mobile"
    compileSdkVersion flutter.compileSdkVersion
    //ndkVersion flutter.ndkVersion
HayesGordon commented 5 months ago

@echogit glad you solved it

RenatTOP commented 2 months ago

I have the same problem. With rive v0.13.12 and ndk ndkVersion "26.1.10909125" I have librive_text.so size on average 45mb. image

With rive v0.9.1 and ndk ndkVersion "25.1.8937393" I have librive_text.so size on average 3.5mb. image

RenatTOP commented 2 months ago

Is there a way to reduce weight without downgrading the rive and ndk version?

HayesGordon commented 2 months ago

HI @RenatTOP, could you please confirm if you can reproduce this with a new Flutter project. There is maybe some combination of your build environment that is going wrong. If you can reproduce it in a new sample app can you please share that and we can investigate.

Some additional information you can share:

Also please ensure you're not also accidentally still setting ndkVersion flutter.ndkVersion