昨天做项目的时候发现,用butterknife绑定的按钮报空指针错误,结果方法压根就没绑定上。用这个文章记录一下配置过程,以防下次还犯。
AndroidStudio3.5 ButterKnife10.2.1
1.安装AS ButterKnife插件,提高开发效率。(安装后需重启)
2.项目引入jar包
android {
...
// Butterknife requires Java 8.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.jakewharton:butterknife:10.2.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'
}
3.add the plugin to your buildscript
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.0'
}
}
4.apply it in your module
apply plugin: 'com.jakewharton.butterknife'
原文链接:https://blog.csdn.net/Lonelyooacz/article/details/102692250