butterknife10.1.0遇到的坑

匿名 (未验证) 提交于 2019-12-03 00:02:01

一、使用步骤

1.在app或者model的build.gradle中:

apply plugin: 'com.jakewharton.butterknife'  android {     compileOptions {//指定Java的版本         targetCompatibility JavaVersion.VERSION_1_8         sourceCompatibility JavaVersion.VERSION_1_8     } }  dependencies{//添加依赖      implementation "com.jakewharton:butterknife:10.1.0"       annotationProcessor "com.jakewharton:butterknife-compiler:10.1.0" }

2.在工程的build.gradle中:

 dependencies{         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:10.1.0"         classpath "com.jakewharton:butterknife-gradle-plugin:10.1.0" }

二、遇到的坑

1.butterknife10.1.0版本需要配合androidx使用

//替换android.support包 implementation 'androidx.appcompat:appcompat:1.0.2'

2.在使用butterknife10.1.0版本时,通过@BindView(R.id.xx)注解无效,控件报NullPointerException错。

原因是我的项目设置支持使用kotlin语言,以上添加依赖是有问题的,添加依赖需要将compiler的依赖改成kapt :

dependencies{//添加依赖      implementation "com.jakewharton:butterknife:10.1.0"       kapt "com.jakewharton:butterknife-compiler:10.1.0" }

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!