使用ButterKnife8版本后,已经调用了ButterKnife.bind(context),方法,并且控件上也加注了@BindView(R.id.xxx),但是项目一运行就报空指针,在网上找了解决方法,最终简书中的方法解决了。
1.Project的build.gradle文件中增加classpath
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2.在Module的build.gradle文件中增加plugin
apply plugin: 'com.neenbedankt.android-apt'
3.在Dependencies中增加下面两句
compile 'com.jakewharton:butterknife:8.0.1'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
本文提供了一种解决ButterKnife 8版本集成问题的方法,包括Gradle配置、插件应用及依赖项添加等步骤,帮助开发者避免空指针异常。
1895

被折叠的 条评论
为什么被折叠?



