1

I have an old Android application that does its communication through Apache HTTP. In order for this to work with Apache 9, I've added

<uses-library android:name="org.apache.http.legacy" android:required="false"/>

into the manifest. From what I can tell, this is supposed to work. But it doesn't, I get an exception because of a missing class. Here's what the stack trace looks like:

Stack Trace

Okay, the library is "supposedly missing" but the stack trace would suggest that at least some of it is there, just not the LineFormatter class (that I'm not even calling directly). My offending code looks like this:

PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(socketFactoryRegistry, new MyDNSResolver());

So to recap: I'm transitioning to Android 9 and am calling a function in Apache HTTP. I believe that I've successfully used the legacy Apache HTTP library but some of its internal classes seem to be missing. What's going on and how can I fix this?

Sander Smith
  • 1,371
  • 4
  • 20
  • 30

1 Answers1

1

I have found simply including org.apache.http.legacy.jar as a build dependency (rather than that manifest directive you are using) resolves the issue.

org.apache.http.legacy.jar

But you should really migrate to the new http classes - using deprecated classes is just asking for trouble eventually. The new classes are better supported.

Dominic Cerisano
  • 3,522
  • 1
  • 31
  • 44
  • I didn't know this was an option, I'll download and try it. But I am concerned - how will this work with previous versions of Android where Apache HTTP IS still being shipped? – Sander Smith Oct 31 '19 at 18:50
  • It is the same library afaik, so including it would just be redundant rather than regressive in that case. Don't forget to remove that manifest directive. – Dominic Cerisano Oct 31 '19 at 18:52
  • If you get conflicts, you might try to exclude the dependency provided by the older Android versions. Not sure exactly how you would do that, but [this](https://stackoverflow.com/questions/21764128/how-do-i-exclude-all-instances-of-a-transitive-dependency-when-using-gradle) has some things you can try. – kenny_k Oct 31 '19 at 18:59
  • In this case, I believe the compiler would simply take the last library included in the build to prevent any conflict. @kenny_k that link does not resolve conflicts, it just prevents library dependencies from being loaded - which is actually the problem here already. – Dominic Cerisano Oct 31 '19 at 22:44