Search code examples
androidbutterknife

Cannot find ButterKnife.bind in Butterknife


I include the butterknife library in my project

implementation 'com.jakewharton:butterknife:9.0.0-rc1'

*************UPDATE******** Added annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc1' still not work.

It shows the following error message when building

21:26:51.121 [ERROR] [system.err] E:\workspace\company\git\shopglobal\android\Smart\app\src\main\java\com\package\smart\scenenew\actiivity\SmartActivity.java:150: 错误: 找不到符号

21:26:51.121 [ERROR] [system.err] ButterKnife.bind(this);

21:26:51.121 [ERROR] [system.err] ^

21:26:51.121 [ERROR] [system.err] 符号: 方法 bind(SmartActivity)

But strangely I can view the source code in the android studio, and the ButterKnife jar is in the right place:

.gradle\caches\transforms-1\files-1.1\butterknife-9.0.0-rc1.aar

It shows normal.

enter image description here


Solution

  • From your post, you only added the library and not the annotation processor. Add this annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc1' to your gradle file - preferably beneath your Butterknife dependency. Build your project.

    Your Butterknife library should look like this:

    dependencies {
      ....
      implementation 'com.jakewharton:butterknife:9.0.0-rc1'
      annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc1'
    }
    

    Good luck!