Android的 - MultipartEntity和依赖性 [英] Android - MultipartEntity and dependencies

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

问题描述

我最近从迁移到Eclipse的Andr​​oid的工作室(我不完全控制这个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 code:


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&GT之间的冲突; httpcomponents org.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的客户端(这也依赖于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天全站免登陆