ViewBinding vs Kotlin Android Extensions

As in title. Is it reasonable to switch to ViewBinding? Personally I never had any problem with Kotlin Android Extensions (and I use them in large projects), but some people pointed out that:

  • they imported incorrect layout extensions (never occured to me)
  • ViewBinding is type safe (just like Kotlin Android Extensions)
  • ViewBinding is null safe (just like Kotlin Android Extensions, just write ?. after view id)



My personal cons of ViewBinding:

  • needs rebuilding project to access newly added views (ugh)
  • access through binding reference (ugh)
  • overkill (generates additional class and requires to integrate view’s code with it instead of making it an independent component)

What are your thoughts?

Related StackOverflow Question

If the only thing you’re doing with ViewBinding is accessing views from your Activity/Fragment then yes, it’s probably overkill.

ViewBinding should be used when you want to set variables on the binding and access them from the layout XML. Very useful for implementing MVVM.

Don’t you need DataBinding to do that?

You’re right, ViewBinding and DataBinding are different things, and I was thinking of DataBinding.

Ignore my previous post.