Kotlin Android View Binding: findViewById vs Butterknife vs Kotlin Android Extension

There are a lot of ways to access views in Android. A quick overview:

enter image description here

My advise would be:

  1. findViewById: old school. Avoid.
  2. ButterKnife: old school, but less boilerplate and some added functionality. Still lacks compile time safety. Avoid if possible.
  3. Kotlin Synthetic: really a elegant cached version of findViewbyId. Better performance and way less boilerplate but still no (real) compile time safety. Will be no longer supported from Kotlin 1.8. Avoid if possible.
  4. ViewBinding: Google’s recommendation nowadays. It’s faster than databinding and prevents logic errors inside XML (hard to debug). I use this option for all new projects.
  5. Data Binding: most versatile option, since it allows code inside XML. Still used on a lot of existing projects. But can slow down build times (uses annotation processor just like ButterKnife) and a lot of logic inside XML has become a bit of anti pattern.

See also: https://www.youtube.com/watch?v=Qxj2eBmXLHg

Funny to note that Jake Wharton (original author of ButterKnife) has now joined Google and works on ViewBinding.

Leave a Comment