alex alex - 1 year ago 220
Android Question

Android - MultipartEntity and dependencies

I recently migrate my project from Eclipse to Android Studio (I do not fully control this IDE yet). In this project, I have a file uploader AsyncTask which send multipart over http. To do this, I use org.apache.httpcomponents. I created following dependencies:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.apache.httpcomponents:httpcore:4.4'
compile 'org.apache.httpcomponents:httpmime:4.4'

In my java AsyncTask code:

MultipartEntityBuilder builder = MultipartEntityBuilder.create();
HttpEntity entity =; // < throw exception

The exception I obtain at startup upload:

Caused by: java.lang.NoSuchFieldError: org.apache.http.message.BasicHeaderValueFormatter.INSTANCE
at org.apache.http.entity.ContentType.toString(
at org.apache.http.entity.mime.MultipartFormEntity.<init>(
at org.apache.http.entity.mime.MultipartEntityBuilder.buildEntity(

I think there is a conflict between
android.jar > httpcomponents
and the
dependency but I don't find a solution to resolve my problem.

Answer Source

I had the same issue - try to use the http-android-client (this also relies on the httmime but requires 4.3). This worked for me:

     dependencies {
  compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: ''
    compile('org.apache.httpcomponents:httpmime:4.3') {
        exclude module: "httpclient"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download