gpt4 book ai didi

java - Okhttp.Builder 中的 ExceptionInInitializerError w/Multidex & Kitkat

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:13:48 26 4
gpt4 key购买 nike

我在运行启用了 Multidex 的 Kitkat 4.4.2 的 VM 上遇到了 ExceptionInInitializerError 异常。

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'

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

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

并使用此代码获取生成器的实例

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()”时发生异常。

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

该问题仅发生在 Kitkat 中。任何想法为什么?我试过降级 Okhttp 库并将其升级到最新版本,但没有成功。

编辑:

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

最佳答案

OkHttp 3.13+ 需要 Android 5+

square/okhttp github页面提到最低要求是Android 5+

Github link

Medium link

如@Jaeger 所述,@fancyjyl 与低于 Android 5 的版本一起使用,我们需要使用 OkHttp 3.12.x,但不建议使用它。

关于java - Okhttp.Builder 中的 ExceptionInInitializerError w/Multidex & Kitkat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55992760/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com