org.apache.http编译错误

时间:2017-03-02 00:13:45

标签: android android-studio gradle android-gradle build.gradle

我的项目有与org.apache.http库相关的编译错误,如此image所示。该项目正在使用api 25进行编译。

我的build.gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "com.seffalabdelaziz.crazyman"
        minSdkVersion 11
        targetSdkVersion 25
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_5
            targetCompatibility JavaVersion.VERSION_1_5
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

2 个答案:

答案 0 :(得分:1)

从API 23+中删除了对Apache HTTP客户端库的支持。见https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client。您必须删除对此库的所有引用。

如上面的链接所述,您可以改为使用HttpURLConnection

答案 1 :(得分:0)

尝试添加

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

所以最后它变成了

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.seffalabdelaziz.crazyman"
        minSdkVersion 11
        targetSdkVersion 25
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}