The procedure for using the ButterKnife is as follows:

1. Add ButterKnife Plugins

Click AndroidStudio – >Preferences – >Plugins – > Select Android ButterKnife Zelezny, click Install, and restart. If not, click Browse Repositories in the bottom center to search

2. Add a ButterKnife dependency

Add the following code to dependencies {} in the build.gradle file of your app Module:

compile 'com. Jakewharton: butterknife: 8.8.1'
annotationProcessor 'com. Jakewharton: butterknife - compiler: 8.8.1'
Copy the code


The common reason why ButterKnife fails to read a control is because apt is configured (e.g., when using a Dagger)

At this time, the second sentence above should be changed into APT, otherwise the corresponding control will not be found. As follows:

apt 'com. Jakewharton: butterknife - compiler: 8.8.1'Copy the code

This means that annotationProcessor and apt cannot be used at the same time


What’s the difference between Android-APT and annotationProcessor?

Android-apt is an Annotation Processing Tool for Android. It is called Annotation Processing Tool in full. It is an APT framework developed by individuals. So the framework stopped updating later, but there are still some projects that use it.

Apt configuration method

1. Build. Gradle for project Module

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com. Android. Tools. Build: gradle: 2.3.3'
        classpath 'com. Neenbedankt. Gradle. Plugins: android - apt: 1.8'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}Copy the code


2. Add the following code to the top of the build of app Module:

apply plugin: 'com.neenbedankt.android-apt'Copy the code


Add dependencies{} to the build of the app Module.

compile 'com. Jakewharton: butterknife: 8.8.1'
apt 'com. Jakewharton: butterknife - compiler: 8.8.1'Copy the code