Parth Thakkar
Parth Thakkar

Reputation: 29

Retrofit -Android 11

I did code for Initialise retrofit to call web services . it works in all other android version . I tried to run it on android 11 but getting below error:-

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.reswaiter, PID: 6102
    java.lang.ExceptionInInitializerError

and here is my code for retrofit below code is not working in android 11

val client = OkHttpClient.Builder()
                .connectTimeout(TIMEOUT.toLong(), TimeUnit.MILLISECONDS)
                .readTimeout(TIMEOUT.toLong(), TimeUnit.MILLISECONDS)
                .addInterceptor(logging)
                .addInterceptor(interceptor)
                .build()

            client.connectTimeoutMillis

            val retrofit = Retrofit.Builder()
                .baseUrl(api_url)
                .addConverterFactory(GsonConverterFactory.create())
                .client(client)
                .build()

Upvotes: 0

Views: 1762

Answers (2)

Pradeep Behera
Pradeep Behera

Reputation: 513

I was getting a similar error in Retrofit. Updating retrofit to 2.8.1 worked for me.

    implementation 'com.squareup.retrofit2:retrofit:2.8.1'
    implementation 'com.squareup.retrofit2:converter-gson:2.8.1'

Upvotes: 0

Parth Thakkar
Parth Thakkar

Reputation: 29

For this solution is I changed target sdk to 29 from 30 in app.gradle and it's works fine.

defaultConfig {
        applicationId "com.reswaiter"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

Upvotes: 1

Related Questions