How do I properly import HttpClient from org.apache on Android using gradle build file? How do I properly import HttpClient from org.apache on Android using gradle build file? android android

How do I properly import HttpClient from org.apache on Android using gradle build file?


I think the httpclient library doesn't include the mime parts, those are in httpmime. This is a transitive dependency of httpclient, but as that is ignored, it won't be taken into account.

Try adding this dependency:

compile "org.apache.httpcomponents:httpmime:4.2.3"


Adding http-mime as a dependency causes httpclient to be included as a transitive dependency, which, for me, resulted in the same warnings as the OP. I had to tell gradle to ignore the transitive dependency:

compile ('org.apache.httpcomponents:httpmime:4.3.5') {    // avoid "is ignored for the default configuration X" warnings     // since httpclient is included in the android SDK.    exclude group: 'org.apache.httpcomponents', module: 'httpclient'}


For Android, there is now available HttpClient 4.3.X repackaged Maven distribution

Project repo: https://github.com/smarek/httpclient-android
Maven tag: cz.msebera.android:httpclient:4.3.+
Published to Maven Central repository

Which in version 4.3.3 includes HttpCore, HttpClient, HttpClient-Cache and HttpMime (all of same version)

Disclaimer: I'm author of said project