正如这里提及, Android M将不再支持Apache HTTP API。文档中写道:
use the HttpURLConnection class instead.
或者
为了继续使用Apache HTTP APIs,必须在build.gradle 文件中先声明下面的编译时依赖:
android { useLibrary 'org.apache.http.legacy' }
如果添加后在bulid.gradle中出现如下错误:
Gradle DSL method not found: 'useLibrary()'
请确保你的gradle版本设置高于1.3.0-rc2
下面是示例(API23):
/build.gradle
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}
/app/build.gradle
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 23
buildToolsVersion '23.0.0'
...
}