QuantumBadger / RedReader

An unofficial open source Android app for Reddit.
GNU General Public License v3.0
2.01k stars 482 forks source link

OkHttp is outdated #1005

Open Cguy7777 opened 2 years ago

Cguy7777 commented 2 years ago

OkHttp 3.x is no longer supported. OkHttp 4.x requires Android 5.0.

I understand upgrading this is not a decision to be taken lightly. I really do hate to remove support for older devices, and there are certainly cool, strange, and interesting Androids (and even non-Androids, such as BB10 phones that run Android 4.x apps) from the past that would be cut off by dropping 4.x support.

However, it strikes me as a bad idea to allow this important library to become out of date for everyone using RedReader on newer devices. Lollipop was released in 2014, and, according to Google, 98.6% of Androids run 5.0 or newer. RedReader seems to have a reputation for being pretty lightweight, so our percentage may be lower. :-)

As I see it, we have two good options:

QuantumBadger commented 2 years ago

Thanks for raising this, it's been on my mind for a while. Agreed that we need to do something about it, although I'd like to avoid deprecating 4.x if possible. We have about 200 active users on Google Play using 4.x (probably more on F-Droid too), and it hasn't shown any signs of decreasing over the last year unfortunately.

One possible alternative is to dynamically choose between OkHttp and the OS's built in HTTP client at runtime, depending on the Android version. This would basically mean adding another HTTPBackend implementation.

The build works correctly with OkHttp 4.9.3 even though its min SDK version is higher than the app's, and the app even launches correctly on a 4.x emulator -- it just crashes when we make the first HTTP request. So I think as long as we don't invoke any OkHttp APIs on 4.x, we should be okay.

@Cguy7777 Would you be interested in creating the alternative implementation of HTTPBackend? The HTTPBackend.getBackend() method would need to dynamically return either the OKHTTPBackend or the other impl depending on the OS version.

Cguy7777 commented 2 years ago

@QuantumBadger To be honest, I've never worked on an HTTP implementation in Android, so I'm not sure I'm the ideal candidate for that, especially considering how important that code is, but I can certainly investigate it more.

I did toy around a bit with upgrading the library in Android Studio, and it seems that the new version is essentially a drop-in replacement without any further work.

Maybe it wouldn't be too much work to have a separate build for 4.x? If we just kept using the current version for older devices, the only code difference between the two builds would be the OkHttp version and minSdkVersion. That seems like it might be a good solution for everyone? Users on 5.0+ get the new library, and perhaps a slightly leaner download (I made an apk for 5.0+ w/ 4.9.3, and it's around 200 kb smaller), and users on 4.x devices could continue using 3.12.13, which presumably would still be far more up-to-date than their built-in system HTTP libraries, if we wanted to use those for providing legacy support.

QuantumBadger commented 2 years ago

Maybe it wouldn't be too much work to have a separate build for 4.x?

@Cguy7777 This is definitely an option, although if possible I'd like to keep one APK for everyone (to avoid complicating the Alpha builds and Google Play uploads). At some point I'll have a go at creating an alternative HTTP implementation, and depending on how many roadblocks I run into I'll consider having separate builds.