Skip to content

Native Library - File Size Reduction? #174

Closed

Description

@rac146

So it looks like the sizes of the Skia library come to about 20 MB for Android and 13 MB for IOS. Is there any way to reduce this by creating custom builds or by another method?

Thanks,
Robert

Activity

  1. djcparker commented on Oct 28, 2016

    @djcparker

    same question from me. 20MB for Android is pretty heavy.
    btw; Matt - loving SkiaSharp - awesome job!

    thanks
    Dave

  2. mattleibow commented on Oct 28, 2016

    @mattleibow
    Contributor

    Just to note the average sizes per platform architecture:

    • iOS/tvOS: ~8MB
    • Android: ~14MB
    • macOS: ~21MB
    • Windows: ~5MB
    • UWP: ~4MB
  3. mattleibow commented on Oct 28, 2016

    @mattleibow
    Contributor

    I think, after looking at this, the Android is a bit large. I must have a look at what gyp is doing when it generates the project. It might be the case that the build is wrong as with Windows: mono/skia#25

  4. mattleibow commented on Oct 28, 2016

    @mattleibow
    Contributor

    I tried a few things, but I can't seem to reduce the size at all. Right now, it IS building release with optimizations, yet it is 15MB vs Windows's 5MB and iOS's 8MB

  5. djcparker commented on Oct 30, 2016

    @djcparker

    it is a big difference.

    The realm.io guys had an interesting post on native sizes: reducing apk size, not sure if it is relevant as I haven't pulled the apk apart..

    For me, between skia and a few other packages my app is a 40MB download.

  6. mattleibow commented on Oct 31, 2016

    @mattleibow
    Contributor

    @djcparker Thanks for those links, trying some options now.
    I'll see if I can get a doc together to help with ideas for reducing apk sizes

  7. added this to the 1.55.1 milestone on Nov 9, 2016
  8. removed this from the 1.55.1 milestone on Nov 18, 2016
  9. mattleibow commented on Dec 2, 2016

    @mattleibow
    Contributor

    @laarmen, thanks for that link. It was very helpful in confirming some not-so-great news. The NDK build already strips the output 😞

    The actual size before stripping is ~35-40 MB and this gets stripped to ~13-16. I tried re-stripping the builds, and stripping all debug and other unused symbols, but was unable to reduce the size.

  10. kekekeks commented on Jan 26, 2017

    @kekekeks
    Contributor

    @mattleibow
    Try to compile with -ffunction-sections -fdata-sections -fno-rtti, link with -gc-sections.

  11. mattleibow commented on Jan 27, 2017

    @mattleibow
    Contributor

    I changed the build scripts, and managed to get an overall reduction of about 4MB on Android, 2.5MB on iOS, 2.5MB on macOS and 1MB for tvOS.

    Not a big drop, but the new sizes are:

    • Android: 59.9MB (4 arch)
    • iOS: 45.5MB (5 arch)
    • macOS: 44.2MB (2 arch)
    • tvOS: 19.4MB (2 arch)
    • Windows 7: 13.4MB (2 arch)
    • Windows 10: 15.4 (3 arch)

    @kekekeks have you been able to get smaller files? I am building and linking almost everything in: core, pdf, svg, codecs, intrinsics.

  12. kekekeks commented on Jan 27, 2017

    @kekekeks
    Contributor

    The smallest of my buillds was 1.7MB for arm32 Android. I was not explicitly excluding anything from build, just linked unused stuff away.

  13. mattleibow commented on Jan 27, 2017

    @mattleibow
    Contributor

    Let me look some more... i think i found that if I run strip after the build, then i can get an iOS arch from 11.5MB to 7.5MB. I need check that all works still, and nothing is getting stripped away.

  14. mattleibow commented on Jan 28, 2017

    @mattleibow
    Contributor

    I have managed to drop iOS/tvOS quite a bit to ~5MB per arch - which is the same as Windows/UWP. macOS is a bit smaller at ~15MB per arch and Android is ~12MB per arch. As I am looking at Linux as well (#90) I notice that it is also ~16MB per arch. I still want to see why Linux/Android/macOS are so much larger, even with the same strict compile/link flags. I even made everything private and am just keeping the C API public (size did drop a bit).

    Basically, everything is ~5MB, except the macOS/Android/Linux builds which are ~15MB.

    @kekekeks were you linking in the GPU bits skgpu=1.
    And, are you able to see what size your build is when you link this stuff in: native-builds/libSkiaSharp_android/jni/SkiaSharp.mk (also not that those flags in the makefile only apply to the final library, not all the others)

  15. 29 remaining items

  16. kentcb commented on May 30, 2017

    @kentcb

    Ah, thanks @djcparker @mattleibow! I've made Jon Douglas (Xamarin) aware of this because I was liaising with him yesterday on this issue. I'll report back if I can get a confirmation it's fixed in alpha.

  17. kentcb commented on May 30, 2017

    @kentcb

    OK, tried switching Bitrise to alpha channel and rebuilding. Unfortunately, it still produces a bloated APK :(

  18. djcparker commented on May 30, 2017

    @djcparker

    @kentcb :( not good.

  19. mattleibow commented on May 30, 2017

    @mattleibow
    Contributor

    I am sure this was fixed. You should try archiving your app. It may not reduce the app size if you are running in Debug to reduce compile times, but I am able to get my app reduced if I Archive, even when I just set the linker to "Link SDK assemblies only".

    This is my test app: https://github.com/mattleibow/SkiaSharpDemo

  20. djcparker commented on May 30, 2017

    @djcparker

    Hmmm, ok. Will try the latest alpha :)

  21. kentcb commented on May 31, 2017

    @kentcb

    @mattleibow I am building with Bitrise. Prior to 15.2 my APK was ~30MB. With 15.2 and no code changes, it's now ~40MB. Cracking open the APK and looking inside shows that the native code is in two places: inside lib and also embedded as a resource inside SkiaSharp.dll. This is true of both stable Xamarin and alpha Xamarin. The bug report is CONFIRMED with no mention of a fix being in place in any channel yet.

  22. mattleibow commented on May 31, 2017

    @mattleibow
    Contributor

    @kentcb If you build my sample app (https://github.com/mattleibow/SkiaSharpDemo) does the same thing happen? I can't seem to reproduce when running "Archive for Publishing".

    What is your IDE and your version numbers?

    Mine are: https://gist.github.com/mattleibow/bff95014b9cee90c828a67f1ed335fc7

  23. kentcb commented on May 31, 2017

    @kentcb

    @mattleibow I work locally with VS, but I don't use that to produce productions APKs/IPAs - they always come through Bitrise. So I'd be comparing apples to oranges if I looked at my VS output.

    Hmmm, I wonder whether it has to do with the Bitrise images. They've upgraded to 15.2.2, but they do not yet include VS4Mac, only XS. There's a small chance that's a factor. Bitrise plan to include VS4Mac in their images sometime in the next week or two. Once they've done that, I'll report back here as to whether that rectifies the problem.

    All the same, Xamarin have confirmed it is an issue, so I assume it still is.

  24. mattleibow commented on Jun 1, 2017

    @mattleibow
    Contributor

    @kentcb I just built Release of my sample app using the stable VS and everything appears to be fine. No need for anything fancy, I just did a plain old Release build on Any CPU. I will point out that the SkiaSharp.dll in the bin folder STILL has the embedded native libraries (9MB), but the one in the .apk does not (200KB).

    Does my sample work for you locally in VS? And in your Bitrise build, could you send ([email protected]) the build log? I will have a look and see what is up.

    Here is my VS config:
    https://gist.github.com/mattleibow/8395177ffec5f0ef61d95ccf0eb0dfe3

  25. kentcb commented on Jun 22, 2017

    @kentcb

    @mattleibow interestingly, my APK dropped from 45MB to 35MB again today when I merged my branch to switch us to netstandard and SDK-style csproj 🤔

  26. EmilAlipiev commented on Jul 1, 2018

    @EmilAlipiev

    Hello, this is crazy. using version 1.60.0, it ads 3,8 mb size while 1.60.1 adds 9mb.. what has changed in between? you didnt even increase major version number. it cant be such a big difference. see this issue

    luberda-molinet/FFImageLoading#893

  27. mattleibow commented on Jul 3, 2018

    @mattleibow
    Contributor

    @EmilAlipiev thanks for reporting this. The build system changed a fair bit and the stripping may have fallen back to the original settings. I opened a new issue #573 and I will see if I can get this resolved ASAP.

  28. mattleibow commented on Jul 3, 2018

    @mattleibow
    Contributor

    Could all new comments be made on the new issue so we can track them with the next release.

  29. EmilAlipiev commented on Nov 30, 2020

    @EmilAlipiev

    I think that size was increased also from 3mb to 5mb between 1.6x version to 2.8x version. it is not a big number but i want to just inform you :)

  30. ghost locked as resolved and limited conversation to collaborators on Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions