Apache HttpClient Android(Gradle)

Hir*_*del 52 android gradle apache-httpcomponents multipartentity android-studio

我已将此行添加到build.gradle中

compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5'
Run Code Online (Sandbox Code Playgroud)

我想在我的代码中使用MultipartEntityBuilder.但Android Studio不会将库添加到我的代码中.谁能帮我这个?

Jin*_*inu 128

如果你在build.gradle中使用target sdk作为23添加下面的代码

android{
 useLibrary  'org.apache.http.legacy'
}
Run Code Online (Sandbox Code Playgroud)

另请注意:不要尝试使用这些文件的gradle版本.他们被打破了(28.08.15).我尝试了5个多小时让它上班.它只是没有. 不工作:

compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
Run Code Online (Sandbox Code Playgroud)

另一件事 不要用:

'org.apache.httpcomponents:httpclient-android:4.3.5.1'
Run Code Online (Sandbox Code Playgroud)

它指的是21 api级别.

  • 只需添加“android{ useLibrary 'org.apache.http.legacy' }”即可解决我的问题。谢谢! (2认同)

ok2*_*k2c 24

接受的答案对我来说似乎不太合适.当一个人可以依赖于它的相同版本时,没有必要拖动不同版本的HttpMime.

compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5'
compile (group: 'org.apache.httpcomponents' , name: 'httpmime' , version: '4.3.5') {
    exclude module: 'org.apache.httpcomponents:httpclient'
}
Run Code Online (Sandbox Code Playgroud)


Pav*_*los 7

尝试将此添加到您的依赖项:

compile 'org.apache.httpcomponents:httpclient:4.4-alpha1'
Run Code Online (Sandbox Code Playgroud)

通常,如果您想使用库并且正在搜索Gradle依赖项,则可以使用Gradle Please

编辑:也检查一下.


San*_*ich 7

没有其他人为我工作.我不得不添加下面的依赖,如解释在这里

compile group: 'cz.msebera.android' , name: 'httpclient', version: '4.4.1.1'
Run Code Online (Sandbox Code Playgroud)

因为我的目标是API 23.