Okhttp.Builder中带有Multidex&的ExceptionInInitializerError奇巧 [英] ExceptionInInitializerError in Okhttp.Builder w/ Multidex & Kitkat

查看:115
本文介绍了Okhttp.Builder中带有Multidex&的ExceptionInInitializerError奇巧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在启用Multidex的情况下运行Kitkat 4.4.2的VM上遇到ExceptionInInitializerError异常.

I'm experiencing an ExceptionInInitializerError exception on VM running Kitkat 4.4.2 with Multidex enabled.

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)
    at myapp.utils.Utils.getHttpClientBuilder(Utils.java:131)
    at myapp.fragments.FragmentHome.getHome(FragmentHome.java:326)
    at 
myapp.fragments.FragmentHome.onViewCreated(FragmentHome.java:135)

我有以下库:

implementation 'jp.wasabeef:recyclerview-animators:3.0.0'
implementation 'com.ashokvarma.android:bottom-navigation-bar:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.ogaclejapan.smarttablayout:utils-v4:2.0.0@aar'
implementation 'com.duolingo.open:rtl-viewpager:1.0.3'
implementation 'com.squareup.retrofit2:retrofit-converters:2.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.14.1'
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation 'com.karumi:dexter:5.0.0'
implementation 'com.nineoldandroids:library:2.4.0'
implementation 'org.jsoup:jsoup:1.11.3'
implementation 'saschpe.android:customtabs:2.0.0'

我正在使用此代码创建改造连接

I'm creating a retrofit connection using this code

Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(Constants.API_LINK)
            .addConverterFactory(GsonConverterFactory.create())
            .client(Utils.getHttpClientBuilder())
            .build();

并使用此代码获取构建器的实例

And getting an instance of the builder using this code

public static OkHttpClient getHttpClientBuilder(){
    return new OkHttpClient.Builder()
            .readTimeout(60, TimeUnit.SECONDS)
            .connectTimeout(60, TimeUnit.SECONDS)
            .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .build();
}

getHttpClientBuilder()方法中调用"build()"时发生异常.

The exception happens when calling "build()" in the getHttpClientBuilder() method.

我还在AndroidManifest.xml中分配了一个默认应用程序,它扩展了MultiDexApplication并在onCreate(Bundle bundle)中具有MultiDex.install(this);.

I also have a default application assigned in the AndroidManifest.xml, it extends MultiDexApplication and has MultiDex.install(this); in onCreate(Bundle bundle).

此问题仅在Kitkat中发生.有什么想法吗?我尝试降级Okhttp库并将其升级到最新版本,但没有成功.

The issue only happens in Kitkat. Any ideas why? I've tried downgrading Okhttp library and upgrading it to the latest version, it didn't work out.

从Retroft构建器中删除客户端不会更改任何内容.错误仍然显示.

Removing the client from the Retroft builder doesn't change anything. The error still shows.

推荐答案

显示应用程序依赖关系树

show app dependencies tree

+--- com.ogaclejapan.smarttablayout:utils-v4:2.0.0
+--- com.duolingo.open:rtl-viewpager:1.0.3
+--- com.squareup.retrofit2:retrofit-converters:2.5.0
+--- com.squareup.okhttp3:logging-interceptor:3.14.1
|    \--- com.squareup.okhttp3:okhttp:3.14.1 (*)
+--- com.squareup.okhttp3:okhttp:3.12.0 -> 3.14.1 (*)

您应该使用3.12.0日志记录拦截器

you should use 3.12.0 logging-interceptor

implementation 'com.squareup.okhttp3:logging-interceptor:3.12.0'

这篇关于Okhttp.Builder中带有Multidex&amp;的ExceptionInInitializerError奇巧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆