组件化中Butterknife使用

  1. 添加依赖
implementation Libs.butterknife
annotationProcessor Libs.butterknife_compiler
  1. 在Library中使用Butterknife

To use Butter Knife in a library, add the plugin to your buildscript:

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

and then apply it in your module:

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

Now make sure you use R2 instead of R inside all Butter Knife annotations.

class ExampleActivity extends Activity {
  @BindView(R2.id.user) EditText username;
  @BindView(R2.id.pass) EditText password;
...
}
  1. 如果项目中使用了apply plugin: 'kotlin-kapt',则需要把上面的annotationProcessor修改为kapt,如下
implementation Libs.butterknife
kapt Libs.butterknife_compiler
  1. 使用kotlin之后还是逐步移除butterknife吧

你可能感兴趣的:(组件化中Butterknife使用)