Any idea why IDE doesn't see the component contributed with anvil? You can see it's gray and unused (also there are red unresolved ref errors in usage sites), but it compiles fine. I can call
myComponent.createCoordinator()
and the instance is created.
If I switch to non-anvil dagger it starts to work. Do I need to include some additional source set? Currently default from kotlin plugin are used
d
Daniel Perez
03/01/2022, 4:38 PM
Pretty sure you have to put
@MergeComponent
on a component.
@ContributesTo
usually goes on a module
d
dimsuz
03/01/2022, 4:54 PM
This is not a final component this is more like
ComponentInterface
from anvil's README. Final component which contains this interface does contain
@MergeComponent
r
ralf
03/01/2022, 6:12 PM
Your
@SingleIn
is wrong. A component interface doesn’t have a Dagger scope.
But to answer your question: no, the IDE unfortunately doesn’t see that the component interfaces are merged and added as super types to the final component. The compiler and IDE don’t provide any hooks for that. That will change with the new compiler frontend that will be shipped with Kotlin 1.8 probably.
d
dimsuz
03/01/2022, 11:01 PM
I see! Any workaround you could advise? I tried to manually make merged component inherit this interface, but then compilation fails with "missing override modifier", and if I add it, then IDE highlights it as incorrect (cause of the above reasons). Catch 22 🙂
I might be wrong above who complains about what, away from code currently, but the thing is that however you try to fix it, manually inheriting doesn't work either during compile time or in the ide.
P.S. Thanks for this single-in pointer, missed this.
r
ralf
03/01/2022, 11:18 PM
We cast the component at runtime to the component interface, because we know it’ll succeed. It’s not the best solution, but works for us.