Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My App is crashing on Android 11 with: java.lang.ExceptionInInitializerError at okhttp3.OkHttpClient

My App is crashing on Android 11 with the following log:

2021-01-01 18:16:52.556 10648-10648/com.myapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.myapp, PID: 10648
    java.lang.ExceptionInInitializerError
        at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:211)
        at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:204)
        at retrofit2.Retrofit$Builder.build(Retrofit.java:628)
        at com.myapp.MyApplication.onCreate
like image 202
Ivo Stoyanov Avatar asked Jan 01 '21 16:01

Ivo Stoyanov


People also ask

What is Java Okhttpclient?

OkHttp is an efficient HTTP & HTTP/2 client for Android and Java applications. It comes with advanced features, such as connection pooling (if HTTP/2 isn't available), transparent GZIP compression, and response caching, to avoid the network completely for repeated requests.

What is the use of Okhttpclient in Android?

OkHttp android provides an implementation of HttpURLConnection and Apache Client interfaces by working directly on a top of java Socket without using any extra dependencies.

What is the use of Okhttpclient in and?

OkHttp is an HTTP client from Square for Java and Android applications. It's designed to load resources faster and save bandwidth. OkHttp is widely used in open-source projects and is the backbone of libraries like Retrofit, Picasso, and many others.

What is the underlying library of OkHttp?

Beginning with Mobile SDK 4.2, the Android REST request system uses OkHttp (v3. 2.0), an open-source external library from Square Open Source, as its underlying architecture. This library replaces the Google Volley library from past releases.


1 Answers

In my case I was using:

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

Updating okHttp to version 4.4.0 fixes the problem.

implementation 'com.squareup.okhttp3:logging-interceptor:4.4.0'
like image 71
Ivo Stoyanov Avatar answered Oct 04 '22 12:10

Ivo Stoyanov