12

I recently tried to migrate the application I'm working on from GCM to FCM. While doing so, I found that where I'd previously been using Dagger 2 (2.0.2) to provide instances of my Retrofit APIs and other user-data managers inside the service (with no problems), I could no longer do so for the FirebaseMessagingService.

Whenever I'd try to compile with a subclass of FirebaseMessagingService listed in my Dagger 2 Component interface, I'd get an IllegalArgumentException. After digging through some code, it seems that the exception is thrown when Dagger 2 tries to validate a class name and finds that the first letter isn't uppercase. FirebaseMessagingService, at least on my end, inherits from a uglified / minified codebase, and its immediate superclass is zzb (public class FirebaseMessagingService extends com.google.firebase.iid.zzb).

My best guess is that this is the culprit. If this really is the problem, I'm not sure what to do about this aside from stick to GCM for now. Anyone have any ideas or similar experience with this?

EDIT: I got the chance to ask one of the Firebase developers about this issue: https://www.reddit.com/r/androiddev/comments/4upj1o/beware_of_the_new_firebase/d5tdbk3 - No resolution. I'm probably just going to avoid direct injection and consolidate to a static API provider.

Carter Hudson
  • 1,176
  • 1
  • 11
  • 23
  • could you add your dependencies to the question? – Arthur Thompson Jun 02 '16 at 20:07
  • I @Inject into a FirebaseMessaging subclass with Dagger 2 and have no problems. Can you post the relevant code of your Component and FirebaseMessagingService subclass so we can help you better? – Uli Aug 17 '16 at 20:10

2 Answers2

7

After half day of struggle, finally moving to Dagger 2.7 fixed the issue.

compile "com.google.dagger:dagger:2.7"
apt "com.google.dagger:dagger-compiler:2.7"
nizam.sp
  • 4,002
  • 5
  • 39
  • 63
0

We had the same issue, Dagger does some silly validation for class uppercase classname and encounters an obfuscated classname, which actually looks like

public class FirebaseService extends xxab {   

}

(xxab is just random name that proguard spits in obfuscation pass and I can remember the exact)

We did silly workaround, not elegant, but worked:

public class FirebaseServiceProvider { //not real provider, though
   public FirebaseServiceProvider(...params){
      mInstance = ...
   }
  public FirebaseService getService(){
   return mInstance;
  }
}

In the @Module:

@Singleton
@Provides
public FirebaseServiceProvider providesFirebaseServiceProvider(){    
 return new FirebaseServiceProvider(.....);
}

Injection:

@Inject
FirebaseServiceProvider mFirebaseServiceProvider;

Usage:

mFirebaseServiceProvider.getService().doStuff();
Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148