Search code examples
androidbutterknife

Unresolved Reference: "ButterKnife"


I am getting the above compiler error, but I can't fix it no matter what I do.

MyActivity

import butterknife.ButterKnife // Unresolved Reference: ButterKnife
import butterknife.BindView // Unresolved Reference: BindView

class MyActivity: AppCompatActivity() {

    @BindView(R.id.textView)
    lateinit var mTextView: TextView

    // ...

}

build.gradle (Project)

buildscript {
    repositories {
        jcenter()
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

build.gradle (Module)

dependencies {
    annotationProcessor 'com.jakewharton:butterknife:10.2.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'
}

What I've tried so far...

  1. Scoured the internet for solutions, including this SO post
  2. Deleted the .idea folder & restart
  3. Invalidate cache & restart
  4. Clean Project
  5. Gradle Sync
  6. Cry

Solution

  • You should use implementation 'com.jakewharton:butterknife:10.2.1' instead of annotationProcessor. This dependency contains your missing package, so it should be implementation or api if you want to use it in your code.

    In this case annotationProcessor is not good for you, because it generally used for code generators, like butterknife-compiler.