38

I am seeing this error when I try to run "gradle build"

WARNING: Dependency org.apache.httpcomponents:httpclient:4.2.3 is ignored for the default configuration as it may be conflicting with the internal version provided by Android. In case of problem, please repackage with jarjar to change the class packages :prepareFreeDebugDependencies :compileFreeDebugAidl UP-TO-DATE :generateFreeDebugBuildConfig UP-TO-DATE :mergeFreeDebugAssets UP-TO-DATE :compileFreeDebugRenderscript UP-TO-DATE :mergeFreeDebugResources UP-TO-DATE :processFreeDebugManifest UP-TO-DATE :processFreeDebugResources UP-TO-DATE :compileFreeDebug /home/xrdawson/Projects/Foo/Bar/src/main/java/com/Foo/app/PixActivity.java:20: error: package org.apache.http.entity.mime does not exist import org.apache.http.entity.mime.HttpMultipartMode; ^ 

The end of my build.gradle looks like this:

 repositories { mavenCentral() } dependencies { compile fileTree(dir: 'libs', include: '*.jar') compile "org.eclipse.mylyn.github:org.eclipse.egit.github.core:2.1.3" compile "com.madgag:markdownj-core:0.4.1" // compile "org.apache.httpcomponents:com.springsource.org.apache.httpcomponents.httpclient:4.2.1" compile 'org.apache.httpcomponents:httpclient:4.2.3' compile "com.google.android:support-v4:r6" } } 

Why is the compile process ignoring HttpClient, but then failing to compile?

6 Answers 6

79

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" 
Sign up to request clarification or add additional context in comments.

5 Comments

Part of httpmime 4.2+ depends on org.apache.http.entity.ContentType that is present in httpcore 4.2+ but NOT present in android.jar (for, at least, APIs 9...19). Hence, you might want to restrict yourself to depend on org.apache.httpcomponents:httpmime:4.1.3 to be fine.
From google,it says that transitive dependency is now solved.Since version 1.0 of the Gradle plugin, we have moved to Gradle 2.2+ which has support for advanced custom dependency resolution. It'll allow you to override any transitive dependency with a different one. This should allow you to fix issues where you depend transitively on a broken dependency.
with this i am not able to use MultipartEntityBuilder. Any alternatives? Finding solution from past 2 days...
@JimitPatel - add follwing in your gradle compile ('org.apache.httpcomponents:httpmime:4.3.5') { exclude group: 'org.apache.httpcomponents', module: 'httpclient' }
I found out the solution... Here is my version - stackoverflow.com/questions/32796770/…
17

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' } 

1 Comment

Lifesaver! This was exactly what Im looking for! Thank you!
13

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

2 Comments

I used this package to help me with AsyncHttp library.
You saved my day
3

Adding to this I solved the Issue by Using This, if your compileSdkVersion is 19(IN MY CASE)

compile ('org.apache.httpcomponents:httpmime:4.3'){ exclude group: 'org.apache.httpcomponents', module: 'httpclient' } compile ('org.apache.httpcomponents:httpcore:4.4.1'){ exclude group: 'org.apache.httpcomponents', module: 'httpclient' } compile 'commons-io:commons-io:1.3.2' 

else if your compileSdkVersion is 23 then use

android { useLibrary 'org.apache.http.legacy' packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' } } 

Comments

2

Because the official Android APIs includes httpclient we remove all dependency on httpclient, including its transitive dependency.

if you really want to use httpclient, I'd repackage it with jarjar, renaming the packages and use this instead.

As for httpmime, it looks like it's not actually in android.jar so we could avoid filtering it out, but for now you would have to add it manually.

We'll probably want to tweak this before the build system goes 1.0

2 Comments

I'm also suffering from this problem. You're answer is a bit confusing. Are you saying that the version of gradle with android studio forces this behavior? There's no way around it short of jarjar?
I am also having this problem. How to include multipart upload support without having to pull in httpmime and get bogged down in this mess?
0

Just add this to build.gradle(Module: app) file:

dependencies { ... implementation "org.apache.httpcomponents:httpmime:4.5.6" } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.