转载自:http://blog.youkuaiyun.com/jiangtianhao13269230/article/details/49447159
出处:http://www.zhihu.com/question/35597452/answer/63619567
Android studio中“import org.apache.http.Header;”没用?
ShinChven,使用:Xperia/Android/OSX/iOS/Ubuntu/Ce…
梁利晖、渡扬子 赞同
Android M 起默认移除了Apache HTTP:https://developer.android.com/intl/zh-cn/preview/behavior-changes.html
要使用的话,要这么干
1、在gradle-wrapper.properties中配置使用较新版本的gradle
distributionUrl=https://services.gradle.org/distributions/gradle-2.6-all.zip
2、在build.gradle中使用较新版本的gradle buildtools
buildscript {
repositories {
jcenter()
}
dependencies {
classpath ‘com.android.tools.build:gradle:1.3.0’
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
3、添加以下依赖,重新使用已经deprecated 的apache http 包:
android {
useLibrary ‘org.apache.http.legacy’
}
4、添加apache http component 的依赖,补全缺失的类,比如Header:
dependencies {
compile ‘org.apache.httpcomponents:httpcore:4.4.2’
}
我只使用了3、4条建议就可以了。