Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OkHttp crashes Android 4.x devices #6188

Closed
JordanLongstaff opened this issue Jul 17, 2020 · 6 comments
Closed

OkHttp crashes Android 4.x devices #6188

JordanLongstaff opened this issue Jul 17, 2020 · 6 comments
Labels
bug Bug in existing code

Comments

@JordanLongstaff
Copy link

A recent version of OkHttp made improvements to the Android platform detector, so that it correctly identifies an Android device if it is running on one. However, these same improvements make my app crash on startup because it cannot start up a NetworkClient because the Android platform detector is expecting an API version >= 21.

07-17 12:07:11.693 3778-3778/com.encircle E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.ExceptionInInitializerError
        ...
        at android.os.AsyncTask.finish(AsyncTask.java:631)
        at android.os.AsyncTask.access$600(AsyncTask.java:177)
        at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5103)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: kotlin.KotlinNullPointerException
        at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:232)
        at okhttp3.OkHttpClient$Builder.build(OkHttpClient.kt:1069)
        ...
        at android.os.AsyncTask.finish(AsyncTask.java:631) 
        at android.os.AsyncTask.access$600(AsyncTask.java:177) 
        at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:137) 
        at android.app.ActivityThread.main(ActivityThread.java:5103) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:525) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
        at dalvik.system.NativeStart.main(Native Method) 

Please support TLS 1.2 in Android API 16-20 in your latest versions. #2372 already explained that those Android APIs support TLS 1.2 and demonstrated how TLS 1.2 can be used with those APIs, and your explanation for requiring API 21 as your minimum version even contains a link to this post explaining how to enable TLS 1.2 on older APIs. As far as I'm concerned, the bump to Android 5+ was needless and caused more problems than it solved.

@JordanLongstaff JordanLongstaff added the bug Bug in existing code label Jul 17, 2020
@JakeWharton
Copy link
Member

How do you support it on devices that don't run play services?

@JordanLongstaff
Copy link
Author

How do you support it on devices that don't run play services?

Google Play Services doesn't seem to matter. When I run the app, I get a notification saying, "[Your app] won't run unless you update Google Play services." Yet it runs fine and I'm able to log in to our server with no problems.

As a formality, I disabled, and then force stopped, Google Play Services. I also cleared all data from Play Services, uninstalled and reinstalled the app, and restarted the phone. Still no problems running the app and logging in.

@swankjesse
Copy link
Member

OkHttp 3.12.x is our branch for apps targeting Android 4.x.

If you’d like to maintain an OkHttp fork that supports old Androids, please do! We will also enthusiastically encourage people to use your fork if it is high quality!

@JordanLongstaff
Copy link
Author

There are already over 8,000 forks of this project. I don't have time to look at every one to see if any of them fix my problem. Are there any that you know that you can "enthusiastically encourage" me to use?

@swankjesse
Copy link
Member

As far as I know, you’d be the first.

@yschimke
Copy link
Collaborator

I'm missing some of the nuance of this discussion. Is the request for

a) an OkHttp version that supports TLSv1.2 on Android 16 -> This is OkHttp 3.12.x
or
b) Avoid eagerly failing OkHttp 4.x on unsupported versions, so against the requirements people can try to use it anyway.

That post (https://medium.com/tech-quizlet/working-with-tls-1-2-on-android-4-4-and-lower-f4f5205629a) you linked to is out of date. OkHttp 3.12.12 does support Android 16, and does negotiate TLSv1.2. There should be no situation where Tls12SocketFactory is actually useful.

See https://github.com/square/okhttp/blob/okhttp_3.12.x/okhttp/src/main/java/okhttp3/internal/platform/AndroidPlatform.java#L442-L465

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in existing code
Projects
None yet
Development

No branches or pull requests

4 participants