Apache HttpClient Android (Gradle)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26024908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache HttpClient Android (Gradle)
提问by Hirad Roshandel
I have added this line to my build.gradle
我已将此行添加到我的 build.gradle
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5'
and I want to use MultipartEntityBuilder in my code. However Android studio doesn't add the library to my code. Can anyone help me with this?
我想在我的代码中使用 MultipartEntityBuilder。但是 Android Studio 不会将库添加到我的代码中。谁能帮我这个?
回答by Jinu
if you are using target sdk as 23 add below code in your build.gradle
如果您使用目标 sdk 作为 23,请在 build.gradle 中添加以下代码
android{
useLibrary 'org.apache.http.legacy'
}
additional note here:dont try using the gradle versions of those files. they are broken (28.08.15). I tried over 5 hours to get it to work. it just doesnt. not working:
附加说明:不要尝试使用这些文件的 gradle 版本。它们坏了 (28.08.15)。我尝试了 5 多个小时才能让它工作。它只是没有。 不工作:
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
another thingdontuse:
另一件事不要使用:
'org.apache.httpcomponents:httpclient-android:4.3.5.1'
its referring 21 api level.
它指的是 21 api 级别。
回答by ok2c
The accepted answer does not seem quite right to me. There is no point dragging a different version of HttpMime when one can depend on the same version of it.
接受的答案对我来说似乎不太正确。当人们可以依赖同一版本的 HttpMime 时,拖动不同版本的 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'
}
回答by Santiago Martí Olbrich
回答by Pavlos
Try adding this to your dependencies:
尝试将其添加到您的依赖项中:
compile 'org.apache.httpcomponents:httpclient:4.4-alpha1'
And generally if you want to use a library and you are searching for the Gradle dependency line you can use Gradle Please
通常,如果您想使用库并且正在搜索 Gradle 依赖项行,则可以使用Gradle Please
EDIT: Check thisone too.
编辑:也检查这个。
回答by sumit mehra
I resolved problem by adding following to my build.gradle file
我通过在 build.gradle 文件中添加以下内容解决了问题
android {
useLibrary 'org.apache.http.legacy'}
However this only works if you are using gradle 1.3.0-beta2 or greater, so you will have to add this to buildscript dependencies if you are on a lower version:
但是,这仅在您使用 gradle 1.3.0-beta2 或更高版本时才有效,因此如果您使用的是较低版本,则必须将其添加到 buildscript 依赖项中:
classpath 'com.android.tools.build:gradle:1.3.0-beta2'
回答by mohamed elagamy
I searched over and over this solution works like a charm ::
我一遍又一遍地搜索这个解决方案就像一个魅力::
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.anzma.memories"
useLibrary 'org.apache.http.legacy'
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('org.apache.httpcomponents:httpmime:4.3.6') {
exclude module: 'httpclient'
}
compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
}
回答by Ketan Ramani
Working gradle dependency
工作gradle依赖
Try this:
尝试这个:
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
编译'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
回答by Nikolay Hristov
I don't know why but (for now) httpclientcan be compiled onlyas a jar into the libs directory in your project. HttpCoreworks fine when it is included from mvn like that:
我不知道为什么,但(目前)httpclient只能作为 jar编译到项目的 libs 目录中。 当HttpCore像这样从 mvn 中包含时,它可以正常工作:
dependencies {
compile 'org.apache.httpcomponents:httpcore:4.4.3'
}