sentry-react-native icon indicating copy to clipboard operation
sentry-react-native copied to clipboard

Reducing library size (specially on Android)

Open ospfranco opened this issue 3 years ago • 5 comments

Hey! I've convinced my team/company to use Sentry to track our errors. However there is one small problem, we are very conservative when it comes to increasing the size of our app (specially on Android), after adding Sentry our .apk size increased from 43.90mb to 45.40mb. This makes it a hard pill to swallow for us, so I have a couple of questions.

  • Is there any possible way to reduce the bundle size with the library as is?
  • Are there any plans/ongoing work to reduce the size of the library further down?

Many thanks!

ospfranco avatar Apr 26 '21 09:04 ospfranco

Just a quick update, after checking the documentation on the android sentry library, a suggestion is to change from the sentry-android dependency to sentry-android-core which drops support for the NDK (means collecting C/C++ stack traces is no longer possible), this seems like it reduces the final apk size (waiting for the final build from my CI to confirm this).

I used patch-package to change the dependency in this library's build.gradle and seems like everything compiles/works just fine.

ospfranco avatar Apr 26 '21 09:04 ospfranco

@ospfranco Yes you should be able to disable the NDK just fine by using the sentry-android-core package. We have also discussed monitoring the package size and considering ways to reduce it, cc @bruno-garcia will have better insight on this.

jennmueng avatar Apr 26 '21 11:04 jennmueng

Going with sentry-android-core only is a good options. It's pure Java 1.8 so no Kotlin std overhead or native code.

Right now that's what we can offer to trim down an Android app. We want to explore more things in the future though.

bruno-garcia avatar Apr 27 '21 02:04 bruno-garcia

maybe we could document how to use sentry-android-core only at least

marandaneto avatar Nov 12 '21 10:11 marandaneto

we believe that the NDK support should be ootb and people that don't want to pay for it due to bundle size, they can use the sentry-android-core SDK, we'll document this on the RN docs.

marandaneto avatar Dec 06 '21 16:12 marandaneto

@ospfranco would you like to give it a try on https://microsoft.github.io/rnx-kit/docs/guides/bundling#tree-shaking ?

marandaneto avatar Aug 30 '22 14:08 marandaneto

Sorry, no longer at the same company, so this is a non-issue for me, but I've been hearing all over twitter that tree-shaking does help :)

As there are workarounds (using sentry-android-code and tree-shaking) you can close this issue if you want to

ospfranco avatar Aug 30 '22 14:08 ospfranco

Thanks for the feedback.

marandaneto avatar Aug 30 '22 14:08 marandaneto