美文网首页
组件化中Butterknife使用

组件化中Butterknife使用

作者: tesla1984 | 来源:发表于2019-11-13 19:03 被阅读0次
  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使用

      本文链接:https://www.haomeiwen.com/subject/fyskictx.html