本文主要是介绍@BindView使用遇到的一些坑 2020-09-02,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
@BindView使用遇到的一些坑
- 先介绍使用方法
引入包build.gradle
如果你的项目使用的是 support包
列
api ‘com.android.support:recyclerview-v7:27.1.1’
dependencies {implementation 'com.jakewharton:butterknife:8.8.1'annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'}
使用方法
@BindView(R.id.frameLayout01)
FrameLayout frameLayout01;
重要的一步
ButterKnife.bind(this);此行代码必须加不然会导致程序崩溃
报错
xxxx has stopped
logcat报错
Caused by: java.lang.ClassNotFoundException: Didn’t find class “android.view.View$OnUnhandledKeyEventListener” on path: DexPathList[[zip file “/data/app/com.xiaocaoer.canvaspath-XsbIg-aFj-9UpfkK9ZBpHQ==/base.apk”],nativeLibraryDirectories=[/data/app/com.xiaocaoer.canvaspath-XsbIg-aFj-9UpfkK9ZBpHQ==/lib/x86, /system/lib, /vendor/lib]]
Caused by: javax.net.ssl.SSLHandshakeException: SSL handshake aborted: ssl=0xb0ab2640: I/O error during system call, Connection reset by peer
Caused by: com.google.android.apps.gsa.shared.exception.GsaIOException: Error code: 393238 | Buffer overflow, no available space.
at com.google.android.apps.gsa.speech.audio.Tee.f(SourceFile:103)
如果你项目中使用的是androidx包
implementation ‘androidx.appcompat:appcompat:1.2.0’
implementation ‘androidx.constraintlayout:constraintlayout:2.0.0’
报错
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.
解决办法
那么你引入的包需要改一下版本,因为10.1.0以下版本依赖使用的support包
修改引入10.1.0版本以上
implementation 'com.jakewharton:butterknife:10.1.0'annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
报错2
com.android.tools.r8.a: Static interface methods are only supported starting with Android N (–min-api 24): void butterknife.Unbinder.lambda$static$0()
com.android.tools.r8.a: Static interface methods are only supported starting with Android N (–min-api 26): void butterknife.Unbinder.lambda$static$0()
原因
仅从Android N开始支持静态接口方法。需要指定java编译版本
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
本人java开发人员,最近因为公司中android需要改一些bug所以学习一些dndroid知识遇到的坑,希望能帮助到你,不对的地方希望android大神指点。
这篇关于@BindView使用遇到的一些坑 2020-09-02的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!