1、Library Dependency 搜索添加butterknife
或 compile 'com.jakewharton:butterknife:8.4.0'
2、 项目的Gradle文件
classpath 'com.android.tools.build:gradle:2.2.3'
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
}
3、 app的Gradle文件
``` apply plugin: 'com.neenbedankt.android-apt'//增加这一句
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.jakewharton:butterknife:8.4.0'//buttetknife
apt 'com.jakewharton:butterknife-compiler:8.4.0'//添加这一句 } ```
4、使用
- 需要在 setContentView() 或 inflate() 之后调用bind,申明的所有对象才会创建出来
- View变量声明的时候不能为private或者static.
- 除了Activity之外,你可以提供其他的View Root,来获取对象(执行注入).
详细使用方法:http://blog.youkuaiyun.com/skeeing/article/details/52386438
5、添加混淆
#ButterKnife
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}
-dontwarn butterknife.Views$InjectViewProcessor
-dontwarn com.gc.materialdesign.views.**