Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataBindingComponent not being generated when using dagger2

When compiling my app, I get the following error on all of my generated WhateverFragmentOrActivityBinding classes:

error: cannot find symbol
  protected WhateverFragmentOrActivityBinding(DataBindingComponent _bindingComponent, View _root,
                                         ^
  symbol:   class DataBindingComponent
  location: class WhateverFragmentOrActivityBinding

The DataBindingComponent class does not seem to be generated.

Having a look at the documentation for DataBindingComponent we see:

If using Dagger 2, the developer should extend this interface and annotate the extended interface as a Component.

I am indeed using Dagger 2, so I suspect that this might be relevant. I've tried to do this myself, to no avail, and could not find it implemented on the internet. This is what I've tried:

@Component(dependencies = [AppComponent::class], modules = [(AppModule::class), (AndroidInjectionModule::class), (ActivityBuilderModule::class)])
interface BindingComponent : DataBindingComponent

However the DaggerBindingComponent class is never generated because of the cannot find symbol errors that I already had. This seems like a chicken and egg issue, so I don't feel confident that this is the solution to my issue.

The DataBindingComponent seems to be responsible for handling BindingAdapters. I have some custom binding adapters for binding an ImageView src property, but even commenting out these adapters does not help, so I'm not sure if they are related.

I tried removing Dagger from the app completely and the issue did not go away. Not sure what else to try

u_u

like image 532
Jason Ridge Avatar asked May 25 '18 11:05

Jason Ridge


Video Answer


2 Answers

I was having this same issue a couple days ago, I was using product flavors and one of them (the one that I was currently working on) did not have access to a class needed, this caused ALL of binding classes to fail, I was getting multiple errors on every Activity or Fragment binding classes.

I was also using Dagger2 and one of my modules did not have access to a class (CustomBroadcastReceiver)

@Module
abstract class BroadcasReceiverModule {

    @ContributesAndroidInjector
    internal abstract fun contributePhoneStateBroadcastReceiver(): CustomBroadcastReceiver
}

this error was never shown after the build process, BroadcastReceiverModule was part of my "main" resources but it was not required for the flavor I was working on where CustomBroadcastReceiver did not exist

even though it was not required it still generated a bunch of errors that disapeared after I removed BroadcastReceiverModule from "main" resources and placed it only on the flavors that it was actually required

like image 107
Eduardo Martinez Avatar answered Oct 08 '22 15:10

Eduardo Martinez


I was having the same error messages.

Then I found that Studio was showing errors when DataBinding is used/built, also build output was not showing more than 100 lines of errors by default so:

https://github.com/google/dagger/issues/306

Added this to build.gradle:

gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xmaxerrs" << "500" // or whatever number you want
    }
}

Then I found the actual error:

https://github.com/google/dagger/issues/1245

https://issuetracker.google.com/issues/115738511

Solution for me was to downgrade Dagger 2.19 to Dagger 2.16.

like image 25
vitorefo Avatar answered Oct 08 '22 17:10

vitorefo