Dagger: Dagger doesn't implement component method if the method is used only in generated code

Created on 27 Mar 2017  路  7Comments  路  Source: google/dagger

Hi,

I've found strange problem when using custom annotation processor in project with Dagger. Minimal working sample here:
dagger-sample-repo-2.zip

Steps to reproduce (as implemented in attached project):

  1. Create MainComponent extending MyFeatureComponent.
  2. Add injection method to MyFeatureComponent.
  3. Create custom annotation processor that generates code that calls feature component's injection method (this method is not called from non-generated code).
  4. Try to compile the project: Build fails with "DaggerMainComponent is not abstract and does not override abstract method inject(MyFeatureFragment) in MyFeatureComponent" - the injection method inherited from MyFeatureComponent to MainComponent is not implemented.

Am I doing something wrong? Tried with latest Dagger version, latest build tools etc. Thanks!

Most helpful comment

Having a problem which is probably related to this issue. Android data binding library generates DataBindingComponent interface which declares methods for providing all the data binding adapters. If I declare my component AppBindingComponent that extends the DataBindingComponent interface and doesn't implement any method of this interface, then generated class doesn't implement any methods as well and I am having DaggerAppBindingComponent is not abstract and does not override abstract method ... in DataBindingComponent. The reason of this, I guess, the same - methods of DataBindingComponent are used only in generated code.

The interesting moment is that if I redeclare all the methods of DataBindingComponent in my interface AppBindingComponent everything is generated properly.

All 7 comments

Having a problem which is probably related to this issue. Android data binding library generates DataBindingComponent interface which declares methods for providing all the data binding adapters. If I declare my component AppBindingComponent that extends the DataBindingComponent interface and doesn't implement any method of this interface, then generated class doesn't implement any methods as well and I am having DaggerAppBindingComponent is not abstract and does not override abstract method ... in DataBindingComponent. The reason of this, I guess, the same - methods of DataBindingComponent are used only in generated code.

The interesting moment is that if I redeclare all the methods of DataBindingComponent in my interface AppBindingComponent everything is generated properly.

I have the same issue. Answer by @iovorobiev helped me until I cleaned project. Every time I clean a project, build fails with error "DaggerBindingComponent is not abstract and does not override abstract method". Simple solution is adding and removing methods from DataBindingComponent after every clean up.

Could you help me?

Dagger 2.13

The same issue here, any new solution now? Thanks!

I believe this is another instance of https://github.com/google/auto/issues/660. As soon as we find a way to fix that cleanly, this should be fixed.

This seems to still be an issue when extending the DataBindingComponent as @iovorobiev said. I was updating an old blog post at the weekend that described how to use DataBindingComponent with Dagger to include Kotlin code samples and I hit the issue when converting the Java samples over to Kotlin.

E.g. This worked fine in Java:

@Component(dependencies = AppComponent.class, modules = BindingModule.class)
public interface BindingComponent extends DataBindingComponent {}

But I had to override the method when the component was written in Kotlin:

@Component(dependencies = [AppComponent::class], modules = [BindingModule::class])
interface BindingComponent : DataBindingComponent {

    override fun getImageBindingAdapter(): ImageBindingAdapter // Won't build without this
}

Versions used: Android Studio 3.4.0, Dagger 2.22.1, Kotlin 1.3.30.
Link to post: https://philio.me/using-android-data-binding-adapters-with-dagger-2/

This seems to still be an issue when extending the DataBindingComponent as @iovorobiev said. I was updating an old blog post at the weekend that described how to use DataBindingComponent with Dagger to include Kotlin code samples and I hit the issue when converting the Java samples over to Kotlin.

E.g. This worked fine in Java:

@Component(dependencies = AppComponent.class, modules = BindingModule.class)
public interface BindingComponent extends DataBindingComponent {}

But I had to override the method when the component was written in Kotlin:

@Component(dependencies = [AppComponent::class], modules = [BindingModule::class])
interface BindingComponent : DataBindingComponent {

    override fun getImageBindingAdapter(): ImageBindingAdapter // Won't build without this
}

Versions used: Android Studio 3.4.0, Dagger 2.22.1, Kotlin 1.3.30.
Link to post: https://philio.me/using-android-data-binding-adapters-with-dagger-2/

You should update your blog post!

This is still an issue, it's confusing to have to override it and have it do nothing, very unintuitive. Google, please create a guide for the use case of injecting a dependency into a BindingAdapter. That blog post is excellent but it's about the only thing on the whole internet that I could find.

This seems to still be an issue when extending the DataBindingComponent as @iovorobiev said. I was updating an old blog post at the weekend that described how to use DataBindingComponent with Dagger to include Kotlin code samples and I hit the issue when converting the Java samples over to Kotlin.
E.g. This worked fine in Java:

@Component(dependencies = AppComponent.class, modules = BindingModule.class)
public interface BindingComponent extends DataBindingComponent {}

But I had to override the method when the component was written in Kotlin:

@Component(dependencies = [AppComponent::class], modules = [BindingModule::class])
interface BindingComponent : DataBindingComponent {

    override fun getImageBindingAdapter(): ImageBindingAdapter // Won't build without this
}

Versions used: Android Studio 3.4.0, Dagger 2.22.1, Kotlin 1.3.30.
Link to post: https://philio.me/using-android-data-binding-adapters-with-dagger-2/

You should update your blog post!

This is still an issue, it's confusing to have to override it and have it do nothing, very unintuitive. Google, please create a guide for the use case of injecting a dependency into a BindingAdapter. That blog post is excellent but it's about the only thing on the whole internet that I could find.

It's a while ago now, I've forgotten how I stumbled upon this. As my example in there post doesn't include this I'll update it.

Was this page helpful?
0 / 5 - 0 ratings