Dagger generates code with wrong parameter names and fails to compile
See original GitHub issueWe 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:
- Created a year ago
- Comments:18
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry, I was out last week.
Just got some time to look into this and should have a fix submitted soon.
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
TestComponent extends
AppComponent
for use in some connected android tests and is written in KotlinActivityComponent a pretty standard subcomponent written in Kotlin
Interestingly when I roll back to Dagger 2.41 the function is declared with a parameter name of
arg0
inDaggerTestComponent
:but in Dagger 2.42 the function parameter name is not replaced with
arg0
, but it’s uses remainarg0
.Interestingly, this suggests a workaround: Anytime you’re doing something like this with a module, just name it
arg0
🤷♀️