Android M(6.0) 中删除Apache HTTP Client的解决方案

一、 引言

以下是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,大家可以自己去试试啦~

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值