一、 引言
以下是google官网的原文叙述:
Android 6.0 release removes support for the Apache HTTP client. If your app is using this client and targets Android 2.3 (API level 9) or higher, use the HttpURLConnection class instead. This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption.
二、概述
众所周知,google 在Android 6.0中删除了org.apche.http.*中的绝大部分类,主要包括了HttpClient的Api。而目前一些主流的框架都用到了httpclient,类似asyhttpclient,UIL等。包括google自己提供的volley里面都涉及到了httpclient,话说这不是google自己打自己的脸么,但是google选择okhttp作为网络传输层的框架自然有它的道理。所以以后的开发,尽量还是要避免使用到httpclient相关的,毕竟google都遗弃它了。好的,废话不多说了,下面看解决方案。
三、解决办法
其实解决办也很简单:
1、对于用android studio的朋友,google官方就有解决方案,就是在 build.gradle 文件中加入以下代码
android {
useLibrary ‘org.apache.http.legacy’
}
2、对于还在用eclipse的朋友,那就是把org.apache.http.legacy.jar这个包加入到项目的libs当中,这个jar包在\sdk\platforms\android-23\optional下面。
ok,大家可以自己去试试啦~