Using Butterknife with Kotlin
The Android world has many libraries that require annotation processing. You just annotate the code, and it generates all the code behind the scenes for you, making your life easier. Many libraries such as Butterknife and Dagger2 work in similar ways. In this recipe, we will learn how to use Butterknife with Kotlin. For those who aren't familiar with Butterknife, it's a library that binds a view to a field without needing the findViewById
calls. It's a household name in the Android development world. In Kotlin, the Kotlin Android Extension does almost the same work and is bundled along with Kotlin. However, if you are migrating your Java code where you've used Butterknife, this recipe will help you.
Getting ready
We will be using Android Studio 3.0 for coding purposes.
How to do it…
To include Butterknife in your project, follow the given steps:
- To start with, add the following lines to your
build.gradle
file; also, you need to add thekotlin-kapt
plugin and replace...