Warning! For Google Analytics users

Tahsin Dane
Sep 28, 2015 · 3 min read

I have a very little open source application called HackDash. It just shows the open/close status of various Hackerspaces in the world in DashClock.

The implementation is really simple. It just uses SpaceAPI to get the directory of all Hackerspaces and uses their internal APIs to show the status of those Hackerspaces.

Apart from the support library and various helper libraries, I only use play-services-analytics from Google Play Services to integrate with Google Analytics.

Today I’ve just upgraded Play Services from version 7.8.0 to 8.1.0 and I realized that my application size increased from 1.7Mb to 1.9Mb. 200Kb for nothing but a library update with no changelog. And Yes! I use ProGuard.

As a good citizen of the Android world, I take care of the sizes of my apps. You should do it too. Why? Here is a great article that explains the importance of it in detail: Putting Your APKs on Diet

I also wrote an article about the problem I saw in Turkish Airlines Android app here. They eventually decreased their APK size from 20.5Mb to ~8Mb.

Let’s get back to the problem and investigate it.

I first run

./gradlew androidDependencies

to see the details and the transitive dependencies of all dependencies. Here are the results:

Transitive dependencies of GMS 7.8.0
Transitive dependencies of GMS 8.1.0

Whoa! What’s happening? We now have Google Ads and App Indexing as a part of Analytics. And we have play-services-basement instead of play-services-base.

When I first saw this basement in this post, I thought that they made another lightweight dependency only for Analytics and Ads and I hoped that it would decrease the size of my APK.

When I looked at the following, it was what I expected. Basement is under base, so it should be smaller, right?

basement is also a dependency of base.

Even if it is probably smaller, analytics having ads package ruins the benefit.

Solution

My quick solution to the problem was to just remove Ads dependency using the following:

compile "com.google.android.gms:play-services-analytics:8.1.0") {
exclude module: 'play-services-ads'
}

And if you are using ProGuard it will warn you about the removal. The ProGuard error actually shows that Tag Manager API in Analytics uses some methods related to advertisement id from Ads package. If you are not using Tag Manager, it will be safe for you to exclude it.

Add this to your ProGuard configuration to ignore the warning.

-dontwarn com.google.android.gms.ads.**

Voila! Our APK size is now back to 1.7Mb

The real solution (I think) is that Google should release another Play Services dependency called play-services-tag-manager which will make our lives easier.

Conclusion

If you have a small application that only uses Google Analytics from Google Play Services, your APK will be immediately bigger when you upgrade your dependency to 8.1.0.

Do what I did above and exclude unnecessary Google Ads package from your APK.

Update: Google just announced that this was a mistake and they are going to fix it in the next release. https://plus.google.com/+GoogleDevelopers/posts/HsSNWEQ6H4e

Update 2: Google Play Services 8.3 is released this week. It was a really fast release. The dependencies look like below now. It now only has a dependency to basement. It is now better than ever! You app size and dex size should be even smaller now.

Dependencies of Analytics SDK in GMS 8.3

Follow me on @tasomaniac and +SaidTahsinDane

Google Developers Experts

Experts on various Google products talking tech.

Google Developers Experts

Experts on various Google products talking tech.

Tahsin Dane

Written by

twitter.com/tasomaniac

Google Developers Experts

Experts on various Google products talking tech.