explaingit

jakewharton/butterknife

25,382JavaAudience · developerComplexity · 2/5Setup · easy

TLDR

Butter Knife was an Android library that replaced repetitive UI wiring code with simple annotations, now officially deprecated, Android's built-in view binding should be used in new projects instead.

Mindmap

mindmap
  root((Butter Knife))
    What it did
      Replaced findViewById
      Annotation based binding
      Click listener shortcuts
    How it worked
      Compile time code gen
      Annotation processing
    Status
      Officially deprecated
      Use view binding instead
    Audience
      Android developers
      Legacy project maintainers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Understand how annotation-based view binding works by studying a well-known, historically important Android library.

USE CASE 2

Maintain existing Android projects that already use Butter Knife and need minor updates without a full migration.

USE CASE 3

Learn how annotation processing at compile time generates boilerplate Java code behind the scenes.

Tech stack

JavaAndroid

Getting it running

Difficulty · easy Time to first run · 30min

Deprecated, new Android projects should use the native view binding feature built into Android Studio instead.

In plain English

Butter Knife was an Android library that reduced repetitive boilerplate code when connecting a user interface layout (the visual elements of an Android screen) to the Java code that controls them. In Android development, developers traditionally had to write many lines of "findViewById" calls, code that searches through the UI layout to locate each button, text box, or image by its ID, then assigns it to a variable. Butter Knife replaced all of that with simple annotations (labels you add directly above a variable or method). For example, instead of writing multi-line lookup code for a text field, you would place "@BindView" above a variable and Butter Knife would wire everything up automatically at compile time, generating the repetitive code for you behind the scenes using a technique called annotation processing. Similarly, instead of creating anonymous listener objects to respond to button clicks, you could annotate a method with "@OnClick" and that method would be called automatically when the button was tapped. Note: Butter Knife is now officially deprecated. Google has since built a native replacement called view binding directly into Android, which accomplishes the same goal more safely and without a third-party library. Existing code using Butter Knife will continue to work, but new projects should use view binding instead. The tech stack is Java.

Copy-paste prompts

Prompt 1
Show me a Butter Knife example that binds a TextView and a Button using @BindView and @OnClick annotations.
Prompt 2
How do I migrate an existing Android project from Butter Knife @BindView to Android's built-in view binding?
Prompt 3
Explain how Butter Knife uses compile-time annotation processing to generate findViewById code automatically.
Prompt 4
What is the direct view binding equivalent of Butter Knife's @OnClick for a button in a Fragment?
Prompt 5
Show me the step-by-step process to remove Butter Knife from an Android project and replace it with view binding.
Open on GitHub → Explain another repo

← jakewharton on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.