However, Android decided that using its deprecated Apache httpclient library was the best option.
Google cares about backward compatibility. As you discover, HttpClient has different APIs with different versions, so if Google updates HttpClient, all existing applications will break. Google must support a consistent public API so that applications written for Android 1.x work with Android 4.x and so on. Unfortunately, Google opted for the HttpClient version, which led to a quick break with the newer HttpClient version APIs.
How can I avoid this exception?
Use jarjar or the equivalent to reorganize your copy of the HttpClient library into a different package name, and then use it.
Changing the org.apache namespace is not an option because this exception is thrown by the closed source library.
Then replace the closed source library with something else. It is clear that if a closed source library requires HttpClient 4.2.2, then this closed source library will not work on Android and is not supported by its developer on Android. Even if you manage to overcome the HttpClient problem (for example, through the ROM module - see below), other problems with this library may well arise in relation to its compatibility with Android.
Or download the Android source code, replace the HttpClient version with your own, create the corrected Android source code, pour the results into the ROM module and install the ROM module on the desired device. Be sure to check all existing applications along the way to make sure that they don’t break due to your changes (most likely use HttpUrlConnection , but they may not be).
source share