question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Firebase breaks Dagger

See original GitHub issue

We recently added a class that extends FirebaseMessagingService to our code base. We use Dagger2 for dependency injection and noticed that our app started to have compilations errors. If we instead just extend Service everything works fine.

When putting verbose stacktrace on we get following stacktrace

Caused by: java.lang.IllegalArgumentException
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:108)
    at dagger.internal.codegen.writer.ClassName.peerNamed(ClassName.java:130)
    at dagger.internal.codegen.SourceFiles.membersInjectorNameForMembersInjectionBinding(SourceFiles.java:266)
    at dagger.internal.codegen.InjectBindingRegistry.registerBinding(InjectBindingRegistry.java:194)
    at dagger.internal.codegen.InjectBindingRegistry.getOrFindMembersInjectionBinding(InjectBindingRegistry.java:256)
    at dagger.internal.codegen.BindingGraph$Factory$RequestResolver.rollUpMembersInjectionBindings(BindingGraph.java:313)
    at dagger.internal.codegen.BindingGraph$Factory$RequestResolver.rollUpMembersInjectionBindings(BindingGraph.java:317)
    at dagger.internal.codegen.BindingGraph$Factory$RequestResolver.lookUpBindings(BindingGraph.java:305)
    at dagger.internal.codegen.BindingGraph$Factory$RequestResolver.resolve(BindingGraph.java:407)
    at dagger.internal.codegen.BindingGraph$Factory$RequestResolver.resolve(BindingGraph.java:410)
    at dagger.internal.codegen.BindingGraph$Factory.create(BindingGraph.java:168)
    at dagger.internal.codegen.BindingGraph$Factory.create(BindingGraph.java:105)

The key part is:

at com.google.common.base.Preconditions.checkArgument(Preconditions.java:108)
    at dagger.internal.codegen.writer.ClassName.peerNamed(ClassName.java:130)

Looking at source we see:

public ClassName peerNamed(String peerClassName) {
  checkNotNull(peerClassName);
  checkArgument(SourceVersion.isIdentifier(peerClassName));
  checkArgument(Ascii.isUpperCase(peerClassName.charAt(0)));
  return new ClassName(packageName(), enclosingSimpleNames(), peerClassName);
}

The line in question is: checkArgument(Ascii.isUpperCase(peerClassName.charAt(0))); the issue is due to FirebaseMessagingService extending com.google.firebase.iid.zzb which is in fact a class starting with a lower case letter. Not sure how I should proceed. Is this validation necessary?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

1reaction
artem-zinnatullincommented, Jun 15, 2016

JFYI: for now you can solve this by indirect class where you can inject dependencies required for service that extends FirebaseInstanceIdService.

Something like this:

class MyFirebaseInstanceIdService extends FirebaseInstanceIdService {

  class DiContainer {
    // Container for dependencies required for MyFirebaseInstanceIdService.

    @Inject Dep1 dep1;
    @Inject Dep2 dep2;
  }

  public void onCreate() {
    DiContainer diContainer = new DiContainer();
    MyApp.get(this).objectGraph().inject(diContainer);

    // Grab dependencies from diContainer.
  }
}
0reactions
digitalbuddhacommented, Jun 16, 2016

Also we were on Dagger 2.02 (shamefully)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dagger 2.8 problem with firebase-inappmessaging-display
I have a project that I user dagger 2.8, the project works perfect with firebase-messaging and firebase-core libs, but when I try to...
Read more >
Firebase Android SDK Release Notes - Google
BREAKING CHANGE: With this release, the BoM no longer contains the ... Introduce Dagger as a dependency injection framework for some parts of...
Read more >
Firebase Dagger | Mass Effect Wiki - Fandom
Firebase Dagger is a multiplayer map in Mass Effect 3. It is located on Ontarom. In single-player, the Galaxy at War mission N7:...
Read more >
Using Dagger in Android apps
The Dagger basics page explained how Dagger can help you automate dependency injection in your app. With Dagger, you don't have to write ......
Read more >
Mass Effect 3 Multiplayer: Firebase Dagger [N7 Destroyer] - YouTube
Mass Effect 3 Multiplayer: Firebase Dagger [N7 Destroyer] ... SAS Soldier Breaks Down Clean House Mission in Call of Duty: Modern Warfare -...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found