Httpclient 依赖错误 Android Studio-Gradle

Httpclient dependency error Android Studio-Gradle

我面临 Gradle 1.3.0 和 Android Studio 1.3.2 的 HttpClient 依赖问题。

对于下面的 gradle 文件,作为 Httpclient 库的一部分的以下包未被解析

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

Gradle 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

defaultConfig {
    applicationId "xxx.xxx.xxxx"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile ('org.apache.httpcomponents:httpcore:4.+') {
        exclude module: 'httpclient'
    }
   compile 'org.apache.httpcomponents:httpclient:4.2.2'
}

尽管在 gradle 文件中明确提到,但必须将 httpclient-4.2.2.jar 移动到 libs 目录才能解决依赖关系。

感谢任何帮助..

我认为 httpclient 库不包括 mime 部分,那些在 httpmime 中。这是httpclient的传递依赖,

尝试添加此依赖项:

compile "org.apache.httpcomponents:httpmime:4.2.3"

查看 behavior changes in Android M 上的文档。 根据您需要指定的文档

android {
    useLibrary 'org.apache.http.legacy'
}

在你的 gradle 脚本中使用 Apache HttpClient 如果你编译 API 23.

只需在 gradle 中添加这一行:

compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'