前言
日期:20190905
分类: bug 日常
问题描述
公司项目,本人小米手机运行问题,报
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/impl/client/DefaultHttpClient
解决问题
网络搜一下,在 Manifest.xml 的 applcaition 节点增加:
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
再深入一步
Google 在 Android M(28) 取消支持 Apache HTTP ,推荐使用 HttpURLConnection 类。
HttpURLConnection 优点:
- 效率更高
- 通过透明压缩和响应缓存来减少网络使用
- 最大限度降低耗电量
继续使用 Apache HTTP API?
- build.gradle 文件声明一下编译时依赖
android {
useLibrary 'org.apache.http.legacy'
}
- AndroidManifest.xml 的 application 声明
<uses-library android:name="org.apache.http.legacy" android:required="false"/>