在Android Studio中使用ButterKnife
ButterKnife是一个注解框架
主页是 http://jakewharton.github.io/butterknife/
github地址是 https://github.com/JakeWharton/butterknife
在project的build.gradle配置
在dependecies中,添加classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
如下所示
buildscript {
repositories {
jcenter()
}
dependencies {
//gradle
classpath 'com.android.tools.build:gradle:2.3.0'
//butterknife
classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
在module的build.gradle配置
1、添加apply plugin: 'com.jakewharton.butterknife'
2、添加依赖compile 'com.jakewharton:butterknife:8.5.1'
和annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
如下所示:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
//butterknife
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}