firebase / flutterfire

πŸ”₯ A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.52k stars 3.92k forks source link

πŸ› [firebase_ml_vision] The latest firebase_ml_vision is increasing the app size by a lot #4767

Closed inceptusp closed 3 years ago

inceptusp commented 3 years ago

Bug report

The latest firebase_ml_vision plugin is including a lot of dependencies that I don't use on my app and this is increasing the app size by ~21 MB

Expected behavior

I haven't worked on this app for a while, so I skipped some versions of the plugin, I upgraded straight from 0.9.6+2 to 0.10.0 but the last time I compiled the app, it was ~12MB and now it's ~38MB. It's okay that you are trying to simplify the use of Firebase plugins, but I think that this plugin, specifically, should continue with manual configuration of the dependencies so that the developer only includes what he will really use.

These libraries were not included in the APK before, for instance: image

I don't use any kind of face detection, for example, or image labeling hence these libraries shouldn't even be in the app.

markusaksli-nc commented 3 years ago

Hi @inceptusp
Could you please provide your flutter doctor -v and flutter pub deps -- --style=compact for the build environment? You are certain the increase in size is only from the newly included ML libraries in the APK? Thank you

inceptusp commented 3 years ago

@markusaksli-nc yes, I am certain that the increase in size is from the included ML libraries... You can see by the screenshot I've attached on the first post. libclassifier_jni.so, libface_detector_v2_jni.so and libtensorflowlite_jni.so are from ML Kit and now, inside the release APK, have a folder under "assets" with some ML Models with ~10MB in size that wasn't there before...

Before: image image

After: image image

If you sum up all these sizes it will be ~21MB...

[√] Flutter (Channel stable, 1.22.5, on Microsoft Windows [versão 10.0.19042.746], locale pt-BR)
    β€’ Flutter version 1.22.5 at C:\Sources\flutter
    β€’ Framework revision 7891006299 (6 weeks ago), 2020-12-10 11:54:40 -0800
    β€’ Engine revision ae90085a84
    β€’ Dart version 2.10.4

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    β€’ Android SDK at C:\Sources\android
    β€’ Platform android-30, build-tools 30.0.3
    β€’ Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    β€’ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    β€’ All Android licenses accepted.

[!] Android Studio (version 4.1.0)
    β€’ Android Studio at C:\Program Files\Android\Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    β€’ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code, 64-bit edition (version 1.52.1)
    β€’ VS Code at C:\Program Files\Microsoft VS Code
    β€’ Flutter extension version 3.18.1

[√] Connected device (1 available)
    β€’ SM J600GT (mobile) β€’ 520075a5592b550d β€’ android-arm β€’ Android 10 (API 29)

! Doctor found issues in 1 category.
markusaksli-nc commented 3 years ago

Could you provide your flutter pub deps -- --style=compact?

inceptusp commented 3 years ago

@markusaksli-nc I don't know how this would help, but here it is...

Dart SDK 2.10.4     
Flutter SDK 1.22.5

dependencies:       
- camera 0.5.8+17 [flutter]
- cupertino_icons 1.0.0
- firebase_analytics 7.0.1 [meta flutter firebase_core firebase_analytics_web firebase_analytics_platform_interface]
- firebase_auth 0.20.0+1 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_web flutter]  
- firebase_core 0.7.0 [firebase_core_platform_interface flutter quiver meta firebase_core_web]
- firebase_crashlytics 0.4.0+1 [flutter stack_trace firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface]
- firebase_messaging 8.0.0-dev.14 [meta flutter firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web]
- firebase_ml_vision 0.10.0 [flutter]
- firebase_performance 0.5.0+1 [flutter firebase_core]
- firebase_remote_config 0.8.0-dev.0 [flutter firebase_core firebase_core_platform_interface firebase_remote_config_platform_interface]    
- flare_flutter 2.0.6 [flutter flare_dart meta]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_localizations 0.0.0 [flutter intl characters collection meta path typed_data vector_math]
- geocoding 1.0.5 [flutter geocoding_platform_interface url_launcher]
- geolocator 6.1.14 [flutter geolocator_platform_interface]
- google_maps_flutter 1.1.1 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface]
- http 0.12.2 [http_parser path pedantic]
- package_info 0.4.3+2 [flutter]
- path 1.8.0-nullsafety.1
- path_provider 1.6.27 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows]
- shared_preferences 0.5.12+4 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows]
- url_launcher 5.7.10 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos url_launcher_windows]- webview_flutter 1.0.7 [flutter]

dev dependencies:
- flutter_launcher_icons 0.8.1 [image args yaml path]
- meta 1.3.0-nullsafety.3

dependency overrides:
- firebase_core 0.7.0 [firebase_core_platform_interface flutter quiver meta firebase_core_web]

transitive dependencies:
- archive 2.0.13 [crypto args path]
- args 1.6.0
- characters 1.1.0-nullsafety.3
- charcode 1.1.3
- collection 1.15.0-nullsafety.3
- convert 2.1.1 [charcode typed_data]
- crypto 2.1.5 [collection convert typed_data]
- ffi 0.1.3
- file 5.2.1 [intl meta path]
- firebase 7.3.3 [http http_parser js]
- firebase_analytics_platform_interface 1.0.3 [flutter meta]
- firebase_analytics_web 0.1.1 [flutter flutter_web_plugins firebase firebase_analytics_platform_interface meta]
- firebase_auth_platform_interface 3.0.1 [flutter meta firebase_core plugin_platform_interface]
- firebase_auth_web 0.3.2+6 [flutter flutter_web_plugins meta http_parser intl firebase_core firebase_core_web firebase_auth_platform_interface js]
- firebase_core_platform_interface 3.0.1 [flutter meta plugin_platform_interface quiver]
- firebase_core_web 0.2.1+3 [firebase_core_platform_interface flutter flutter_web_plugins meta js]
- firebase_crashlytics_platform_interface 1.1.6 [flutter meta collection firebase_core plugin_platform_interface]
- firebase_messaging_platform_interface 1.0.0-dev.10 [flutter meta firebase_core plugin_platform_interface]
- firebase_messaging_web 0.1.0-dev.5 [flutter flutter_web_plugins meta firebase_core firebase_core_web firebase_messaging_platform_interface js service_worker]
- firebase_remote_config_platform_interface 0.1.0-dev.0 [flutter meta firebase_core plugin_platform_interface]
- flare_dart 2.3.4
- flutter_plugin_android_lifecycle 1.0.11 [flutter]
- flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math]
- geocoding_platform_interface 1.0.1+1 [flutter meta plugin_platform_interface]
- geolocator_platform_interface 1.0.8 [flutter meta plugin_platform_interface vector_math]
- google_maps_flutter_platform_interface 1.1.0 [flutter meta plugin_platform_interface stream_transform collection]
- http_parser 3.1.4 [charcode collection source_span string_scanner typed_data]
- image 2.1.19 [archive xml meta]
- intl 0.16.1 [path]
- js 0.6.2
- matcher 0.12.9 [stack_trace]
- path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter]
- path_provider_macos 0.0.4+8 [flutter]
- path_provider_platform_interface 1.0.4 [flutter meta platform plugin_platform_interface]
- path_provider_windows 0.0.4+3 [path_provider_platform_interface meta path flutter ffi win32]
- pedantic 1.9.2 [meta]
- petitparser 3.1.0 [meta]
- platform 2.2.1
- plugin_platform_interface 1.0.3 [meta]
- process 3.0.13 [file intl meta path platform]
- quiver 2.1.5 [matcher meta]
- service_worker 0.2.4 [js]
- shared_preferences_linux 0.0.2+4 [file flutter meta path path_provider_linux shared_preferences_platform_interface]
- shared_preferences_macos 0.0.1+11 [shared_preferences_platform_interface flutter]
- shared_preferences_platform_interface 1.0.4 [meta flutter]
- shared_preferences_web 0.1.2+7 [shared_preferences_platform_interface flutter flutter_web_plugins meta]
- shared_preferences_windows 0.0.1+3 [shared_preferences_platform_interface flutter ffi file meta path path_provider_platform_interface path_provider_windows]
- sky_engine 0.0.99
- source_span 1.7.0 [charcode collection meta path term_glyph]
- stack_trace 1.9.6 [path]
- stream_transform 1.2.0
- string_scanner 1.0.5 [charcode meta source_span]
- term_glyph 1.1.0
- typed_data 1.3.0-nullsafety.3 [collection]
- url_launcher_linux 0.0.1+4 [flutter]
- url_launcher_macos 0.0.1+9 [flutter]
- url_launcher_platform_interface 1.0.9 [flutter meta plugin_platform_interface]
- url_launcher_web 0.1.5+1 [url_launcher_platform_interface flutter flutter_web_plugins meta]
- url_launcher_windows 0.0.1+3 [flutter]
- vector_math 2.1.0-nullsafety.3
- win32 1.7.4 [ffi]
- xdg_directories 0.1.2 [meta path process]
- xml 4.5.1 [collection convert meta petitparser]
- yaml 2.2.1 [charcode collection string_scanner source_span]
nateshmbhat commented 3 years ago

facing same issue. The plugin's build.gradle includes all the ML libraries which is increasing the app size to more than twice the original size of the app.

nateshmbhat commented 3 years ago

@markusaksli-nc my pub deps output is as follows :

master└─ $ flutter pub deps -- --style=compact
Dart SDK 2.11.0-213.1.beta
Flutter SDK 1.23.0-18.1.pre
flutter_card_scanner 0.0.1

dependencies:
- camera 0.7.0+1 [flutter camera_platform_interface pedantic quiver]
- firebase_ml_vision 0.10.0 [flutter]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- intl 0.16.1 [path]

dev dependencies:
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]

transitive dependencies:
- async 2.5.0-nullsafety.1 [collection]
- boolean_selector 2.1.0-nullsafety.1 [source_span string_scanner]
- camera_platform_interface 1.5.0 [flutter meta plugin_platform_interface cross_file stream_transform]
- characters 1.1.0-nullsafety.3
- charcode 1.2.0-nullsafety.1
- clock 1.1.0-nullsafety.1
- collection 1.15.0-nullsafety.3
- cross_file 0.1.0 [flutter http meta]
- fake_async 1.2.0-nullsafety.1 [clock collection]
- http 0.12.2 [http_parser path pedantic]
- http_parser 3.1.4 [charcode collection source_span string_scanner typed_data]
- matcher 0.12.10-nullsafety.1 [stack_trace]
- meta 1.3.0-nullsafety.4
- path 1.8.0-nullsafety.1
- pedantic 1.9.2 [meta]
- plugin_platform_interface 1.0.3 [meta]
- quiver 2.1.5 [matcher meta]
- sky_engine 0.0.99
- source_span 1.8.0-nullsafety.2 [charcode collection path term_glyph]
- stack_trace 1.10.0-nullsafety.2 [path]
- stream_channel 2.1.0-nullsafety.1 [async]
- stream_transform 1.2.0
- string_scanner 1.1.0-nullsafety.1 [charcode source_span]
- term_glyph 1.2.0-nullsafety.1
- test_api 0.2.19-nullsafety.2 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- typed_data 1.3.0-nullsafety.3 [collection]
- vector_math 2.1.0-nullsafety.3

Flutter Doctor

master└─ $ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[βœ“] Flutter (Channel beta, 1.23.0-18.1.pre, on Linux, locale en_US.UTF-8)

[βœ“] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[!] Android Studio (not installed)
[βœ“] IntelliJ IDEA Community Edition (version 2020.2)
[βœ“] VS Code (version 1.52.1)
[βœ“] Connected device (1 available)
donemerson commented 3 years ago

Me too :/

Vivamaster commented 3 years ago

Faced the same issue. Is there any solution?

kreativityapps commented 3 years ago

Can it be because 024a11cfe50e492e2ec46774d9cd32c34d894bc3 ?

MaxHumme commented 3 years ago

Can it be because 024a11c ?

Sure seems like some app build.gradle stuff was unnecessarily copied into the main build.gradle...

MaxHumme commented 3 years ago

A workaround for now could be to exclude the .so files you don't need in your app's build.gradle, so they won't be included in the build:

android {
    ...
    // Unnecessarily packaged .so files by firebase_ml_vision package
    packagingOptions {
        exclude 'lib/**/libclassifier_jni.so'
        exclude 'lib/**/libface_detector_v2_jni.so'
        exclude 'lib/**/libtensorflowlite_jni.so'
    }
}
jaumard commented 3 years ago

As a workaround I manually delete those lines from the ml_vision Gradle file:

implementation 'com.google.android.gms:play-services-vision-face-contour-internal:16.0.3'
        implementation 'com.google.android.gms:play-services-vision-image-labeling-internal:16.0.5'
        implementation 'com.google.android.gms:play-services-vision-image-label:18.0.5'
        implementation 'com.google.firebase:firebase-ml-vision-face-model:20.0.2'
        implementation 'com.google.firebase:firebase-ml-model-interpreter:22.0.4'

Like this we're back to normal size APK, PR could easily be done but not sure it will be accepted let me know

Salakar commented 3 years ago

Hey all, :wave:, the firebase_ml_vision package is now discontinued since its APIs have been deprecated and removed from the Android & iOS Firebase SDKs.

I'd recommend switching to the alternatives now;

Apologies for any inconvenience here and best of luck switching over the the new APIs. firebase_ml_custom is not affected by this deprecation.

Thanks

jaumard commented 3 years ago

Are you kidding me?? After 5 month the only solution you officially give is to migrate to a new package... And cherry on the cake that package is not even compatible with iOS and not part of FlutterFire... What a replacement...

Apologies for any inconvenience here and best of luck switching over the the new APIs. firebase_ml_custom is not affected by this deprecation.

Miracle will be more useful than luck in this case.

inceptusp commented 3 years ago

@jaumard add to that that the mentioned package is not even Google officials and is not a proper replacement as it hasn't support for the camera stream... Which is different from the admob case where there IS an official replacement and with great support...

Salakar commented 3 years ago

Don't shoot the messenger πŸ™ˆ we on FlutterFire wrap the iOS and Android SDKs and vision has gone from the Firebase SDKs;

Android:

image

iOS: image

...and the new standalone on-device sdk is nothing to do with Firebase anymore.


To expand, you can replicate most of the Cloud vision APIs now via the easy to deploy Firebase Extensions, e.g. translate text, image labelling, sentiment analysis, text extraction, perspective toxicity analysis - and others in progress.

As for on device APIs - there is no official Flutter package that I'm aware of. Any work we've been doing on packages outside of Core, Auth, Crashlytics, Functions, Firestore, Storage and Messaging has been in our (@invertase) own personal time - there's only so much of this we can do and spending a lot of time writing a brand new plugin when we do a lot already elsewhere is not something we have the time for right now - hence the community plugin being suggested.

I was considering sending PRs to google_ml_kit to add iOS support over the weekend if my personal time permits.

jaumard commented 3 years ago

I know firebase ml vision is now gone... and I'm not asking you or anyone to work on your free time to an equivalent if you don't want too :)

My message is not agains you, I'm blaming the poor communication and management on this... It has been 5 month we're waiting a fix for this so it was already a blocker (at least for me I can't talk for the others ^^) so instead of discontinued the package out of the blue it would have been nice to have a fix and then discontinued it so people have time. Here we were already blocked are now even more blocked because there is no real alternative. I wanted to migrate my app to null safety and do a new release of my app. I'll probably get delayed by weeks (maybe month I don't really know) because of that.

Another good approach would have been to contact google about this (maybe it has been done I don't know) saying ok you discontinued this but there is no equivalent so maybe you can jump on this and provide something. I don't know but I'm sure things could have been more smooth than just => we're done deal with it

TusharPatel18 commented 3 years ago

Hey all, πŸ‘‹, the firebase_ml_vision package is now discontinued since its APIs have been deprecated and removed from the Android & iOS Firebase SDKs.

I'd recommend switching to the alternatives now;

  • for on-device vision APIs; switch to Google's standalone ML Kit library via google_ml_kit
  • for cloud vision APIs; the recommended approach now is to use Firebase Authentication and Functions, which gives you a managed, serverless gateway to the Google Cloud Vision APIs. For an example Functions project see the vision-annotate-images sample project. You'd deploy this project for example and then call the cloud function from your app with your image data to get the annotation result.

Apologies for any inconvenience here and best of luck switching over the the new APIs. firebase_ml_custom is not affected by this deprecation.

Thanks

same problem occurs while using google_ml_kit package.. don't know how to exclude this unnecessary libraries from assets folder im using this package for barcode image scanning to get result please someone help me to exclude which unnecessary lib and model,ill help me to reduce apk size a lot