I am using butterknife 8.0.1
, but a nullpointerexception
is appearing.
This line is on my build.grade file:
compile \'com.ja
App Level(build.gradle)
apply plugin: 'android-apt'
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
}
Project Level(build.gradle)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
Config Butterknife on build.gradle file like this,
compile("com.jakewharton:butterknife:8.5.1")
annotationProcessor "com.jakewharton:butterknife-compiler:8.5.1"
It works for me.
I used this library in Fragment and has NPE. My code was:
ButterKnife.bind(view);
But it was wrong. Library need to know two objects:
1) Target - with annotations @BindView
2) Source - with views
It will be right to write:
ButterKnife.bind(this, view);
When this - your fragment, and view - view of this fragment.
I had this issue too, just because I've added butterknife from Android Studio's Dependency management and not by copy-pasting gradle lines from Butterknife website.
So I had to add
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
instead of just
compile 'com.jakewharton:butterknife:8.5.1'
If you use kotlin:
make sure to use this dependency in module app:
dependencies {
implementation 'com.jakewharton:butterknife:10.0.0'
kapt 'com.jakewharton:butterknife-compiler:10.0.0'
}
From JakeWharton
Yes that plugin is no longer needed. You're already using annotationProcessor for the 'butterknife-compiler' artifact which is built-in to the Android Gradle plugin.
Then the solution is delete apt classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'