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.

Dagger generates code with wrong parameter names and fails to compile

See original GitHub issue

We recently updated Dagger from 2.37 to 2.42. Dagger time to time generates not compiling code. We have a component that uses other component.

Our simplified component;

@Subcomponent
interface ParentComponent {

    fun inject(foo: Foo)

    fun plus(module: FooModule): FooComponent
}

Generated code;

    @Override
    public FooComponent plus(FooModule module) {
      Preconditions.checkNotNull(arg0);
      return new FooComponentImpl(applicationComponentImpl, parentComponentImp, arg0);
    }

Generated code has module parameter but code expects arg0 name. This fails to compile. If i change something in generated code and compile again, old generated code invalided and dagger generate correct code. But issue appears again, I couldnt find a common use case.

As workaround we changed module parameter name in ParentComponent to arg0 and it seems to prevents the issue up until now.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:18

github_iconTop GitHub Comments

1reaction
bcorsocommented, Jul 12, 2022

Sorry, I was out last week.

Just got some time to look into this and should have a fix submitted soon.

1reaction
designedbyzcommented, Jul 8, 2022

Seeing this as well, but interestingly, only in a test component that inherits from another component;

Our (simplified) usage in an Android app looks something like this:

Application component pretty standard android here; written in Kotlin

@Singleton
@Component(modules = [ApplicationModule::class])
interface AppComponent {
    @Component.Builder
    interface Builder {

        @BindsInstance
        fun application(application: Application): Builder

        fun build(): AppComponent
    }

    fun plusActivityComponent(activityModule: ActivityModule): ActivityComponent
...
}

TestComponent extends AppComponent for use in some connected android tests and is written in Kotlin

@Singleton
@Component(modules = [ApplicationModule::class])
interface TestComponent : AppComponent {

    @Component.Builder
    interface Builder {

        @BindsInstance
        fun application(application: Application): Builder

        fun build(): TestComponent
    }
...
}

ActivityComponent a pretty standard subcomponent written in Kotlin

@Subcomponent(modules = arrayOf(ActivityModule::class))
@ActivityScoped
interface ActivityComponent {
...
}

Interestingly when I roll back to Dagger 2.41 the function is declared with a parameter name of arg0 in DaggerTestComponent:

  @Override
  public ActivityComponent plusActivityComponent(ActivityModule arg0) {
    Preconditions.checkNotNull(arg0);
    return new ActivityComponentImpl(testComponent, arg0);
  }

but in Dagger 2.42 the function parameter name is not replaced with arg0, but it’s uses remain arg0.

    @Override
    public ActivityComponent plusActivityComponent(ActivityModule activityModule) {
      Preconditions.checkNotNull(arg0);
      return new ActivityComponentImpl(testComponentImpl, arg0);
    }

Interestingly, this suggests a workaround: Anytime you’re doing something like this with a module, just name it arg0 🤷‍♀️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dagger 2 component not generated - Stack Overflow
In build.gradle's app, you need to add necessary dependencies for Dagger to generate corresponding classes, as below:
Read more >
Deep dive into Dagger generated code (part 2) - ProAndroidDev
This component won't compile: Dagger's annotation processor fails with [Dagger/MissingBinding] java. lang. String cannot be provided without an ...
Read more >
Using Dagger in your Android app - Kotlin
In this codelab, you'll build an Android app that uses Dagger to do Dependency Injection.
Read more >
Assisted Injection With Dagger and Hilt - RayWenderlich.com
Annotate the class name with @AutoFactory so that AutoFactory will process it and generate code. Use @Provided to annotate the bitmapFetcher , ...
Read more >
Contexts and Dependency Injection - Quarkus
To generate the index just add the following plugin to your build file: ... 1, Value is a group id for a dependency...
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