Retrofit: Retrofit version 2.6.0 crashes on pre L devices

Created on 20 Aug 2019  路  1Comment  路  Source: square/retrofit

When I run app on any device below API 21 it crashes with this crash log

Process: com.mindvalley.analytics, PID: 10575
java.lang.ExceptionInInitializerError
at okhttp3.OkHttpClient.(OkHttpClient.kt:211)
at okhttp3.OkHttpClient$Builder.build(OkHttpClient.kt:944)
at com.mindvalley.analytics.apicalls.APIUtil.getAnalyticsClient(APIUtil.kt:52)
at com.mindvalley.analytics.apicalls.APIUtil.getIdentify(APIUtil.kt:26)
at com.mindvalley.analytics.tracking.RegisterDeviceToPubSub.registerDeviceToPubSub(RegisterDeviceToPubSub.kt:31)
at com.mindvalley.analytics.tracking.RegisterDeviceToPubSub.(RegisterDeviceToPubSub.kt:26)
at com.mindvalley.analyticsApp.MainActivity$onCreate$1.(MainActivity.kt:16)
at com.mindvalley.analyticsApp.MainActivity.onCreate(MainActivity.kt:16)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
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$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$Builder.build(OkHttpClient.kt:944)聽
at com.mindvalley.analytics.apicalls.APIUtil.getAnalyticsClient(APIUtil.kt:52)聽
at com.mindvalley.analytics.apicalls.APIUtil.getIdentify(APIUtil.kt:26)聽
at com.mindvalley.analytics.tracking.RegisterDeviceToPubSub.registerDeviceToPubSub(RegisterDeviceToPubSub.kt:31)聽
at com.mindvalley.analytics.tracking.RegisterDeviceToPubSub.(RegisterDeviceToPubSub.kt:26)聽
at com.mindvalley.analyticsApp.MainActivity$onCreate$1.(MainActivity.kt:16)聽
at com.mindvalley.analyticsApp.MainActivity.onCreate(MainActivity.kt:16)聽
at android.app.Activity.performCreate(Activity.java:5231)聽
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)聽
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)聽
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)聽
at android.app.ActivityThread.access$800(ActivityThread.java:135)聽
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)聽
at android.os.Handler.dispatchMessage(Handler.java:102)聽
at android.os.Looper.loop(Looper.java:136)聽
at android.app.ActivityThread.main(ActivityThread.java:5017)聽
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:779)聽
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)聽
at dalvik.system.NativeStart.main(Native Method)聽

I checked few forums where it says okhttp3 has removed the support for Android 4.
Does this also mean retrofit will not work for devices below API 21?

Most helpful comment

OkHttp 3.13 (and newer), per its change log, only supports API 21 and newer. Retrofit 2.6.0 will continue to work with OkHttp 3.12, but you should consider dropping support for pre-21 at some point in the future as bug fixes, security fixes, and performance improvements in OkHttp will only be added to newer version. Also, Retrofit 2.7.0 plans to drop support for pre-API 21 as well.

>All comments

OkHttp 3.13 (and newer), per its change log, only supports API 21 and newer. Retrofit 2.6.0 will continue to work with OkHttp 3.12, but you should consider dropping support for pre-21 at some point in the future as bug fixes, security fixes, and performance improvements in OkHttp will only be added to newer version. Also, Retrofit 2.7.0 plans to drop support for pre-API 21 as well.

Was this page helpful?
0 / 5 - 0 ratings