Okhttp: new OkhttpClient() crash on android 4.4

Created on 19 Mar 2019  Â·  12Comments  Â·  Source: square/okhttp

version:3.14.0
android-version:4.4

crash-code:
new OkhttpClient();

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

java8 is already configured

why?

log:

03-19 13:01:19.857 25428-25428/com.syiyi.vote E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.syiyi.vote, PID: 25428
java.lang.ExceptionInInitializerError
at okhttp3.OkHttpClient.newSslSocketFactory(OkHttpClient.java:263)
at okhttp3.OkHttpClient.(OkHttpClient.java:229)
at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:1015)
at com.syiyi.vote.util.ConfigManager.loadConfig(ConfigManager.kt:16)
at com.syiyi.vote.page.main.MainActivity$hmasTest$1.run(MainActivity.kt:69)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5314)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:680)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: Expected Android API level 21+ but was 19
at okhttp3.internal.platform.AndroidPlatform.buildIfSupported(AndroidPlatform.java:238)
at okhttp3.internal.platform.Platform.findPlatform(Platform.java:202)
at okhttp3.internal.platform.Platform.(Platform.java:79)
at okhttp3.OkHttpClient.newSslSocketFactory(OkHttpClient.java:263) 
at okhttp3.OkHttpClient.(OkHttpClient.java:229) 
at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:1015) 
at com.syiyi.vote.util.ConfigManager.loadConfig(ConfigManager.kt:16) 
at com.syiyi.vote.page.main.MainActivity$hmasTest$1.run(MainActivity.kt:69) 
at android.os.Handler.handleCallback(Handler.java:733) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5314) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:680) 
at dalvik.system.NativeStart.main(Native Method) 

bug

Most helpful comment

All 12 comments

@swankjesse We see same issueCaused by: java.lang.IllegalStateException: Expected Android API level 21+ but was 19 on API level 19 .We use okhttp version 3.4.1 .Ideally 3.4.1 should support API level 19.Problem is we are not able to reproduce locally but we see crashes in playstore .
Do you see any issue with okhttp 3.4.1 on API level 19 ? .Can you please help on this .

Thank you,
Manjunath Kallannavar

@manjunath143 How certain are you that you're using 3.4.1? When you make a request on a recent device what does the user-agent header say?

@swankjesse thanks for reply. We have hard coded okhttp version under dependency section like below
dependencies {

compile "com.squareup.okhttp3:okhttp-urlconnection:3.4.1"
compile 'com.squareup.okhttp3:okhttp:3.4.1'

}
user-agent on API 19
generic_x86; google_sdk_x86-eng 4.4.2 KK 4255240 test-keys; Android SDK built for x86; SDK 19; Android 4.4.2
user-agent on API 28
generic_x86_64; sdk_gphone_x86_64-userdebug 9 PSR1.180720.075 5124027 dev-keys; Android SDK built for x86_64; SDK 28; Android 9

We are not able to reproduce locally but one of our customer see crashes in playstore

Thank you

@swankjesse is there any way to check what version of okhttp is being use in apk ?

Easiest is to look at the user-agent header, or the Version.java class.

You can also run ./gradlew :app:dependencies to see the resolved version

On Fri, May 31, 2019 at 8:23 AM Jesse Wilson notifications@github.com
wrote:

Easiest is to look at the user-agent header, or the Version.java class.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/square/okhttp/issues/4746?email_source=notifications&email_token=AAAQIEKX2WGFOAFUC3NR2NDPYEKDRA5CNFSM4G7NF3H2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWVCIFY#issuecomment-497689623,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAQIEMAGGKH3PV7EHPNZMDPYEKDRANCNFSM4G7NF3HQ
.

If you still have this problem check: https://github.com/square/okhttp/issues/4622#issuecomment-588261353

Expected Android API level 21+ but was 29

I am getting the following error, Does it have solution
java.lang.ExceptionInInitializerError
at okhttp3.OkHttpClient.(OkHttpClient.kt:211)
at okhttp3.OkHttpClient.(OkHttpClient.kt:204)
at com.google.firebase.crashlytics.internal.network.HttpRequest.(HttpRequest.java:43)
at com.google.firebase.crashlytics.internal.network.HttpRequestFactory.buildHttpRequest(HttpRequestFactory.java:43)
at com.google.firebase.crashlytics.internal.common.AbstractSpiCall.getHttpRequest(AbstractSpiCall.java:113)
at com.google.firebase.crashlytics.internal.settings.network.DefaultSettingsSpiCall.invoke(DefaultSettingsSpiCall.java:80)
at com.google.firebase.crashlytics.internal.settings.SettingsController$1.then(SettingsController.java:200)
at com.google.firebase.crashlytics.internal.settings.SettingsController$1.then(SettingsController.java:193)
at com.google.android.gms.tasks.zzo.run(com.google.android.gms:play-services-tasks@@17.2.0:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.firebase.crashlytics.internal.common.ExecutorUtils$1$1.onRun(ExecutorUtils.java:60)
at com.google.firebase.crashlytics.internal.common.BackgroundPriorityRunnable.run(BackgroundPriorityRunnable.java:27)
at java.lang.Thread.run(Thread.java:923)
Caused by: java.lang.IllegalStateException: Expected Android API level 21+ but was 29
at okhttp3.internal.platform.AndroidPlatform$Companion.buildIfSupported(AndroidPlatform.kt:370)
at okhttp3.internal.platform.Platform$Companion.findPlatform(Platform.kt:204)
at okhttp3.internal.platform.Platform$Companion.access$findPlatform(Platform.kt:178)
at okhttp3.internal.platform.Platform.(Platform.kt:179)
at okhttp3.OkHttpClient.(OkHttpClient.kt:211) 
at okhttp3.OkHttpClient.(OkHttpClient.kt:204) 
at com.google.firebase.crashlytics.internal.network.HttpRequest.(HttpRequest.java:43) 
at com.google.firebase.crashlytics.internal.network.HttpRequestFactory.buildHttpRequest(HttpRequestFactory.java:43) 
at com.google.firebase.crashlytics.internal.common.AbstractSpiCall.getHttpRequest(AbstractSpiCall.java:113) 
at com.google.firebase.crashlytics.internal.settings.network.DefaultSettingsSpiCall.invoke(DefaultSettingsSpiCall.java:80) 
at com.google.firebase.crashlytics.internal.settings.SettingsController$1.then(SettingsController.java:200) 
at com.google.firebase.crashlytics.internal.settings.SettingsController$1.then(SettingsController.java:193) 
at com.google.android.gms.tasks.zzo.run(com.google.android.gms:play-services-tasks@@17.2.0:2) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
at com.google.firebase.crashlytics.internal.common.ExecutorUtils$1$1.onRun(ExecutorUtils.java:60) 
at com.google.firebase.crashlytics.internal.common.BackgroundPriorityRunnable.run(BackgroundPriorityRunnable.java:27) 
at java.lang.Thread.run(Thread.java:923) 

Below are the configuration of my Gradle.

implementation 'com.squareup.okhttp:okhttp:2.7.5'
implementation 'com.google.firebase:firebase-crashlytics:17.2.2'

minSdkVersion 21
targetSdkVersion 30

Fixed on okhttp 4.9.0

Still getting issue on api 19 using okhttp 4.9.0 .. issue not fixed!

@davidlad123 OkHttp 4.9.0 doesn't support API 19. https://square.github.io/okhttp/security/

Was this page helpful?
0 / 5 - 0 ratings