Android - MultipartEntity 和依赖项 [英] Android - MultipartEntity and dependencies

查看:31
本文介绍了Android - MultipartEntity 和依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将我的项目从 Eclipse 迁移到 Android Studio(我还没有完全控制这个 IDE).在这个项目中,我有一个文件上传器 AsyncTask,它通过 http 发送多部分.为此,我使用 org.apache.httpcomponents.我创建了以下依赖项:

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

<小时>

在我的 java AsyncTask 代码中:


In my java AsyncTask code:

MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody(...);
builder.addBinaryBody(...);
builder.addBinaryBody(...);
HttpEntity entity = builder.build(); // < 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(ContentType.java:153)
    at org.apache.http.entity.mime.MultipartFormEntity.<init>(MultipartFormEntity.java:52)
    at org.apache.http.entity.mime.MultipartEntityBuilder.buildEntity(MultipartEntityBuilder.java:226)
    at org.apache.http.entity.mime.MultipartEntityBuilder.build(MultipartEntityBuilder.java:230)

<小时>

我认为 android.jar > 之间存在冲突httpcomponentsorg.apache.httpcomponents 依赖项,但我没有找到解决我的问题的方法.


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

推荐答案

我遇到了同样的问题 - 尝试使用 http-android-client(这也依赖于 httmime 但需要 4.3).这对我有用:

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: '4.3.5.1'
  compile('org.apache.httpcomponents:httpmime:4.3') {
      exclude module: "httpclient"
  }
}

这篇关于Android - MultipartEntity 和依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆