参考自:https://blog.csdn.net/haoyuegongzi/article/details/102483787
项目添加butterknife依赖,解脱了不断的findViewById,但是添加依赖后遇到几个问题:
1.通过ButterKnife插件生成的onViewClick(View view)方法无效,后来发现两个依赖都需要用到
`//butterknife
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'`
2.Static interface methods are only supported starting with Android N (–min-api 24): void butterknife.Unbinder.lambda$static$0()
提示的意思是 AndroidStudio中minSdkVersion最小值应为24,其实将24改为26后编译运行,发现,继续提示上面的错误,不同的是24变成26了。但是由于App 肯定不能只适配 8.0以上的设备 , 所以还得解决
解决办法:在app build:gradle 中的android 下添加 指定jdk版本的代码,如下:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
3.The given artifact contains a string literal with a package reference ‘android.support.v4.content’ that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.
该原因可以这样理解:是引用的依赖版本比较老,未适配Androidx,将butterknife版本更新到最新版本10.0.0即可