今天在自测时,项目跑到红米4.4的手机上Okhttp报错java.lang.ExceptionInInitializerError
,详细日志如下:
看到这个错误信息Caused by: java.lang.IllegalStateException: Expected Android API level 21+ but was 19
,应该是版本的问题,去okhttp查了一下原来是自己没仔细看介绍
要想支持5.0一下的需要用okhttp的fix分支3.12.x版本,而我项目里面用的是
implementation("com.squareup.okhttp3:okhttp:3.14.1")
修改为 implementation("com.squareup.okhttp3:okhttp:3.12.0")
即可解决,特此记录一下,看来集成三方开源库时还是要时不时的看看人家的介绍。