相信好多同学在Androidx下使用butterknife注解框架时会遇到各种坑,下面分享下我的踩坑记录,希望可以帮助到大家
1.安装butterknife插件
这一步骤相信大家都可以自己完成,最主要的是下面几个步骤
2.在build.gradle(Project: )中添加如下代码
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
//
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
3.在build.gradle(Module: )中
1).在本页面最上面加入下面这行代码
apply plugin: 'com.jakewharton.butterknife'
2).注入依赖
android {
...
// Butterknife requires Java 8.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
}
这样我们就完成了框架的配置工作,接下来快去你的代码中体验一下吧