1.在整个工程的.gradle的dependencies中添加 classpath:
classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8’
buildscript {
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
2.在需要使用工程的.gradle中plugin添加
apply plugin: ‘com.neenbedankt.android-apt’
之后在dependencies中添加
compile ‘com.jakewharton:butterknife:8.0.1’
apt ‘com.jakewharton:butterknife-compiler:8.0.1’
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile 'com.jakewharton:butterknife:8.0.1'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
}
3.之后在设置中的Plugins里面搜索ButterKnife插件安装就可以使用了
PS:
更新 Android Studio2.3.3到3.0版本后,同时也更新了gradle到4.1后,方式有所改变,只需要在moudle的dependencies中添加
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
compile 'com.jakewharton:butterknife:8.8.1'
其余全部注释掉即可