kotlin-inject icon indicating copy to clipboard operation
kotlin-inject copied to clipboard

Unable to resolve viewbinding classes.

Open evant opened this issue 4 years ago • 2 comments

If you reference a generated viewbinding class in your component or @Inject constructor, it will cause an error. I suspect this is because ksp runs before the viewbinding code gen. You can work around it by wrapping the class so it is resolved:

@JvmInline
value class Binding(val value: MainActivityBinding)

@Component MainActivityComponent(@get:Provides val binding: Binding) { ... }

@Inject class MainScreen(binding: Binding) {
   private val binding = binding.value
   ...
}

evant avatar Oct 25 '21 01:10 evant

Maybe it's possible to check if viewBindung is enabled for the project and set up a mustRunAfter in these cases?

PaulWoitaschek avatar Aug 05 '22 22:08 PaulWoitaschek

There may be some gradle hackery to make this work, but it's not something I really want to explore, I've done enough of that in the past. If someone else is brave enough feel free to post your findings here.

evant avatar Aug 05 '22 23:08 evant