ButterKnife 8版本在AndroidStudio中的配置

使用ButterKnife8版本后,已经调用了ButterKnife.bind(context),方法,并且控件上也加注了@BindView(R.id.xxx),但是项目一运行就报空指针,在网上找了解决方法,最终简书中的方法解决了。

http://www.jianshu.com/p/bf9018c1a7f6

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'

你可能感兴趣的:(Android基础)