ButterKnife 8.0.1
@BindView 失败,空指针异常,跟踪进去,发现是XXXFragment的 XXXFragment$$ViewBinder 的类没有生成。
经过google。发现了解决方案。记录一下。
ButterKnife 8.0.1 not working
Per the readme, you need to include the butterknife-compiler
in order for the generated code to be produced automatically:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
compile 'com.jakewharton:butterknife:8.0.1'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
}
Without this there is no generated code to be loaded and thus none of the fields get set.
You can verify ButterKnife is working by calling ButterKnife.setDebug(true)
and looking in Logcat
简单的说呢。就是之前只加了
compile 'com.jakewharton:butterknife:8.0.1'
没有加上
apt 'com.jakewharton:butterknife-compiler:8.0.1'
所以要在Module的build.gradle 加上
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
在app 的build.gradle
顶部加上
apply plugin: 'com.neenbedankt.android-apt'
dependencies
加上
compile 'com.jakewharton:butterknife:8.0.1'
apt 'com.jakewharton:butterknife-compiler:8.0.1'