kotlin-inject
kotlin-inject copied to clipboard
Unable to resolve viewbinding classes.
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
...
}
Maybe it's possible to check if viewBindung is enabled for the project and set up a mustRunAfter in these cases?
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.