[JAVA] Clean your code with Butter Knife

Introduction

I researched various things about Butter Knife 8 series (Ver.8.5.1), so it is a summary.

What is Butter Knife?

Butter Knife is a View Injection library for Android. View and field methods can be linked using annotations. Click here for GitHub.

Premise

Introduction

Excerpt from README.

build.gradle


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

annotationProcessor is a Gradle plugin Ver.2.Requires 2 or more. If you can't, add the apt library.


 [Gradle settings for using APT in Android projects](http://qiita.com/taki4227/items/9fa2a2368ed5414d0897)


#### **`build.gradle`**
```python

buildscript {
  repositories {
    mavenCentral()
   }
  dependencies {
    classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
  }
}

apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'

Note that using the above plugin will change the ID when binding the View from R to R2.

How to use

It's all written on the Official Site. I will add it later. .. ..

Convenient plugin

There is a plugin that automatically generates ButterKnife's View Injection in one shot. As far as Release Notes is seen, the latest Ver.1.5.0 supports ButterKnife Ver.8.0.1, so it can be used. Can be used.

However, since the android: id described in XML is automatically generated in the variable name of camel case, it seems that it is not suitable when migrating existing code to Butter Knife. Convenient for new use.

Butter Knife Zelezny Click here for Butter Knife Zelezny Plugin Installation Method.

Ver. Migration

What you need to do when upgrading from an older version.

Less than Ver.6 → 7

You can go to the following site.

Ver.7 → 8 It is mostly written on the following site, but only the build.gradle part is added.

Demerit

There was an article that describes the disadvantages of Butter Knife, so I will leave it. Goodbye Butter Knife. I liked you without APT

Similar library

reference

Recommended Posts

Clean your code with Butter Knife
[Rails] Organize your code neatly with gem active_decorator
Clean up findViewById from source code with DataBindingLibrary
Docker management with VS Code
Summary of using Butter Knife
Automate your work with Rake
Format Ruby with VS Code
Hello World with VS Code!
Tune your query with EXPLAIN
Reduce verbose code with Lombok