Compatibility with Dagger2
When i trying to inject some fields into viewModel with Dagger2, it fails, because apt compiler cannot find ActivityMainBinding (generated binding class). Same issue when injecting into Activity, because it extends class with generic type that has no exist yet at APT compile stage. PS: i use Kotlin 1.0, but this issue also should be reproduceable in plain Java
example, that failed to compile https://github.com/deviant-studio/Android-ViewModelBinding/commit/e9417c5bc7badf441236597a74426dde4bf6c3f9
Does it work with plain data binding? I mean without ViewModelBinding library but with some data binding usage.
Well, if generic type of injectable class is ViewDataBinding child (or other autogenerated class), dagger will fail. The only workaround i found is to wrap all injectable fields into some helper class and inject into instance of that class. But it looks ugly :)
example
class DaggerSingletones {
init {
App.getMainComponent().inject(this)
}
@Inject lateinit var service: RestService
@Inject lateinit var db: DB
}
and yes, it works ok with simple plain databinding usage without generics https://github.com/zaki50/realm_template/blob/master/app/src/main/java/com/example/realm_template/MainActivity.java