组件化中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吧
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容