- 添加依赖
implementation Libs.butterknife
annotationProcessor Libs.butterknife_compiler
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;
...
}
- 如果项目中使用了
apply plugin: 'kotlin-kapt'
,则需要把上面的annotationProcessor修改为kapt,如下
implementation Libs.butterknife
kapt Libs.butterknife_compiler
- 使用kotlin之后还是逐步移除butterknife吧
网友评论