Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jhutarek opened this issue Mar 27, 2017 · 7 comments

Comments

@jhutarek
Copy link

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!

@iovorobiev
Copy link

iovorobiev commented Aug 22, 2017

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.

@Nynuzoud
Copy link

Nynuzoud commented May 28, 2018

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

@IvanBean
Copy link

IvanBean commented Nov 3, 2018

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

@ronshapiro
Copy link

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

@Philio
Copy link

Philio commented Apr 23, 2019

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/

@tpfaff
Copy link

tpfaff commented Oct 28, 2020

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.

@Philio
Copy link

Philio commented Oct 29, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants