okhttp3 ExceptionInInitializerError异常解决方案

okhttp3 在Android4.4上出现下面异常

    java.lang.ExceptionInInitializerError
        at okhttp3.OkHttpClient.newSslSocketFactory(OkHttpClient.java:263)
        at okhttp3.OkHttpClient.<init>(OkHttpClient.java:229)
        at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:1015)

解决方案

Okhttp创建一个分支用OkHttp3.12.x来支持Android4.x设备,所以把版本号改为3.12.x即可

implementation 'com.squareup.okhttp3:okhttp:3.12.x'

原文参考链接:https://medium.com/square-corner-blog/okhttp-3-13-requires-android-5-818bb78d07ce

你可能感兴趣的:(Android学习笔记)