Background notifications bloat
Last time we created a super small Android application for our website. However, it is always important to remind of yourself by pushing notifications to keep our users up to date 😉
Adding notifications is a very straightforward process with the help of the Firebase Cloud Messaging (FCM) platform. FCM guides us as soon as we create a new project. Following the guide we add a few things to our Android app project:
the google-services.json file
the google-services Gradle plugin
the Firebase dependency
That is not so many dependencies, huh? Our app is still made of a single Java class and a single activity. That is just 2 classes with 4 methods, 0 class fields and 2 annotations when looking into app's internals. However now the Firebase dependency adds lots of code. Look at the numbers in the table below. That's how much code entities we have got.
New dependency increased the app size 50-100 times from from 10KB up to 1.1MB. It's still 367KB when optimised, which is still gross taking into account how little functionality we added.
A detailed examination gives us an insight on the dependency internals. Besides its own code Firebase requires support classes from other packages such as AndroidX.
Among added high level packages are:
android.support.v4
androidx
com.google.android.datatransport
com.google.android.gms
com.google.errorprone.annotations
com.google.firebase
javax.inject
When it comes to the supporting google-services plugin, it in fact only transfers ids from the google-services.json by adding strings to res/values/strings.xml and res/value/public.xml. Finally, it also puts the corresponding references in the R$string class.
Secondly, Firebase got us a bunch of resource files. Those are color, drawable in several formats, a few notification layouts and many other values.
In values directories we can find localisation files that translate error messages into 85 locals. These XML files cause a bit of “meh” feeling because the messages would never show up in our app even if we disable Google Play Services.
Without a detailed analysis it’s hard though to conclude what exact XML and PNG files are odd here. Same is relevant for the code. However, what is clear now is that the overhead for a little added functionality is significant even when the standard shrinking tools are used. In the next round, we will find out which part of the code actually works.