工作环境(蓝色粗体字为特别注意内容)
1,系统环境:Win7 Ultimate sp1
2、开发环境:AndroidStudio 3.2.1、JDK8u11
3、参考文献:https://www.jianshu.com/p/c61172bfa49b、https://blog.csdn.net/sxk874890728/article/details/78367726
Step1:打开File->Settings->Plugins
Step2:在搜索框中搜索ButterKnife, 再点击search in respositories,选择Android ButterKnife zelezny,最后点击Install.
Step3:在build.gredle(Project)文件中的dependencies标签下添加:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
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
}
Step4:在app的build.gredle 中添加:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compile 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}
sync一下,测试例程:
@BindView(R.id.hello)
TextView textView;
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"hello",Toast.LENGTH_LONG).show();
}
});
注:如果写成“ apt 'com.jakewharton:butterknife-compiler:8.4.0'”会出现报错:
android-apt plugin is incompatible with the Android Gradle plugin. Please use 'annotationProcessor'