Firebase and Dexguard

When migrating from GCM to FCM I discovered that the application crashes when I made a build with dexguard on. I got a cup of tea and sat down for this one. First I wanted to know what the exception was, therefore I made an debug build with the same dexguard rules as a release build. I triggered the crash again and saw the following message

Attempt to invoke virtual method ‘java.lang.String com.google.firebase.iid.FirebaseInstanceId.getToken(java.lang.String, java.lang.String)’ on a null object reference

Clearly some classes were obfuscated that made this crash happen. To fix this issue I added two lines in the dexguard configuration file.

-keep,allowshrinking class com.google.firebase.** { *; }
-keepresourcexmlelements manifest/application/**

The first line speaks for itself. Keep classes that come from the package com.google.firebase. But only using this line still causes the application to crash. When dexguard tries to shrink the manifest it will strip out the services that firebase merges in. To verify this I created an APK with and without the keepresources on. The output is the following

Without keeping the resources, dexguard is nuking the meta data key. After I added those two lines the application was able to run without crashing.

2 Comments

Add a Comment

Your email address will not be published. Required fields are marked *