rainyl / opencv_dart

OpenCV bindings for Dart language and Flutter. Support Asynchronous Now!
https://pub.dev/packages/opencv_dart
Apache License 2.0
136 stars 18 forks source link

package size question #282

Closed abdelaziz-mahdy closed 2 weeks ago

abdelaziz-mahdy commented 2 weeks ago

Question

when looking at the macos and ios package size its the same with ffmpeg and without it ?

android is a little bit better but its still big i think (if there is a way to improve it we can check it )

windows and linux got the highest change which is awesome

rainyl commented 2 weeks ago

@abdelaziz-mahdy Do you mean that comparing to the former single package with prebuilt libs?

Yes, the package sizes of macos, ios and android are increased, I am not sure the reason for macos and ios, but for android, it's because flutter doesn't strip the compiled library (.so), you can confirm this by extracting apk file and inspecting the libdartcv.so (by running file libdartcv.so, it shows not stripped) inside it, you can compare it with the prebuilt libdartcv.so from the releases of dartcv (shows stripped). I have searched how to make flutter strip it but without useful solutions, you can try to work on this.

I guess the reason for macos and ios might be similar, another possible reason is that, different subspec inside DartCvMacOS (https://github.com/rainyl/dartcv/blob/main/DartCvMacOS.podspec#L73) are all packed without stripping by the cocoapods, since I am not very familiar with the building process of cocoapods, i am not sure.

Anyway, it would be nice if we can manage to reduce the package size.

abdelaziz-mahdy commented 2 weeks ago

I meant comparing the opencv_core and opencv_dart, also what do you mean by not stripped? is it not stripping the not needed symbols? or the file is included in the build when it should not be included?

rainyl commented 2 weeks ago

oh sorry for my misunderstanding .

the sizes of opencv_dart and opencv_core are actually different for all platforms, isn't it ? (97.82M vs 81.72M on macos) except iOS without much difference, since the ffmpeg used in this project is under lgpl license, it has to be linked with shared library, i don't know how to add .dylib correctly in podspec, so ffmpeg is not supported on iOS for now.

as for the stripping, it means remove unnecessary symbols from the shared library, you can unzip the built APK file and find the libdartcv.so inside it, and run file libdartcv.so, it will tell some messages with "not stripped", and you can manually strip it with strip command.

abdelaziz-mahdy commented 2 weeks ago

oh sorry for my misunderstanding .

the sizes of opencv_dart and opencv_core are actually different for all platforms, isn't it ? (97.82M vs 81.72M on macos) except iOS without much difference, since the ffmpeg used in this project is under lgpl license, it has to be linked with shared library, i don't know how to add .dylib correctly in podspec, so ffmpeg is not supported on iOS for now.

as for the stripping, it means remove unnecessary symbols from the shared library, you can unzip the built APK file and find the libdartcv.so inside it, and run file libdartcv.so, it will tell some messages with "not stripped", and you can manually strip it with strip command.

oh, can we add the strip in the build of the android ? like from gradle or something?

rainyl commented 2 weeks ago

oh, can we add the strip in the build of the android ? like from gradle or something?

I figured it out, the default configuration of gradle externalNativeBuild is RelWithDebInfo (Release with debug info), by explicitly set -DCMAKE_BUILD_TYPE=Release it will use Release (without debug info), I will open a PR.

abdelaziz-mahdy commented 2 weeks ago

oh, can we add the strip in the build of the android ? like from gradle or something?

I figured it out, the default configuration of gradle externalNativeBuild is RelWithDebInfo (Release with debug info), by explicitly set -DCMAKE_BUILD_TYPE=Release it will use Release (without debug info), I will open a PR.

Nice, hopefully it becomes better

rainyl commented 2 weeks ago

@abdelaziz-mahdy I find that flutter build macos will build an universal app consisted of x86_64 and arm64, so one of MACOS and MACOS_ARM should be deleted, and mark it as MACOS_UNIVERSAL. would you mind to work on this?

abdelaziz-mahdy commented 2 weeks ago

@abdelaziz-mahdy I find that flutter build macos will build an universal app consisted of x86_64 and arm64, so one of MACOS and MACOS_ARM should be deleted, and mark it as MACOS_UNIVERSAL. would you mind to work on this?

Would you mind pointing me out to where I should do the changes and how to check if it works correctly?

rainyl commented 2 weeks ago

I mean just remove one of the report items of MACOS, image

abdelaziz-mahdy commented 2 weeks ago

Oh that one, okay that's easy to do, will do it after class

I thought the binary itself, my bad