【安卓学习之常见问题】 编译android8.0问题- ‘The import org.apache.http.HttpEntity cannot be resolved‘.

█ 【安卓学习之常见问题】 编译android8.0问题- ‘The import org.apache.http.HttpEntity cannot be resolved’.

█ 问题:

● 由于某些原因要使用android8.0的特性,因此将原来的编译环境从android4.4.2(target=android-19)升级到android5.0.1(target=android-21),编译没有出问题,再次升级到android8.0.0(target=android-26),就出现编译问题
 ● 编译下,在appcompat\res\values-v23\styles_base.xml出现如下问题:

★The project was not built since its build path is incomplete. Cannot find the class file for
★org.apache.http.NameValuePair. Fix the build path then try building this project
★The method sqrt(float) is undefined for the type FloatMath
★The type org.apache.http.NameValuePair cannot be resolved. It is indirectly referenced from required .class
★The method ceil(float) is undefined for the type FloatMath
★BasicNameValuePair cannot be resolved to a type
★HttpPost cannot be resolved to a type
★NameValuePair cannot be resolved to a type
★HttpClient cannot be resolved to a type
★HTTP cannot be resolved to a variable
★HttpEntity cannot be resolved to a type
★EntityUtils cannot be resolved
★HttpResponse cannot be resolved to a type
★DefaultHttpClient cannot be resolved to a type

这里写图片描述

█ 解决:

● 1.这些问题都比较好解决,网上都有很多教程,一个一个百度,如The import org.apache.http.HttpEntity cannot be resolved,就是找不到对应的类。The method sqrt(float) is undefined for the type FloatMath,就是找不到对应的方法。

● 2.FloatMath.sqrt和FloatMath.ceil方法过时:直接替换为(float) Math.ceil和(float) Math.sqrt
    PS:Math.ceil和Math.sqrt的返回值是double类型,有必要的情况下,需要进行类型转换!

● 2.HttpClient库:进入apache官网,下载【4.5.5.zip 】
这里写图片描述

Release 4.5.5

HttpClient 4.5.5 (GA) is a maintenance release that fixes a regression introduced
by the previous release causing a NPE in SystemDefaultCredentialsProvider.
Please note that as of 4.4 HttpClient requires Java 1.6 or newer.
Last Published: 2018-01-22

下载之后如下:
   这里写图片描述
    PS:这边我们主要用到httpclient-4.5.5.jar和httpcore-4.4.9.jar两个库
 
█ 总结:

● 由于android sdk将部分库删掉,所以只能使用新的sdk,就需要添加删掉的那些库

这里写图片描述
这里写图片描述
 
下载地址:httpcomponents-client-4.5.5-bin和src_20180518.zip-CSDN下载(org.apache.http的相关类,android高版本SDK需要用到,解决’The import org.apache.http.HttpEntity cannot be resolved’>等问题)

● 由于引入了V7和新的sdk,将导致另一个问题的产生:

[Dex Loader] Unable to execute dex: Cannot merge new index 66457 into a non-jumbo instruction!
[XXX] Conversion to Dalvik format failed: Unable to execute dex: Cannot merge new index 66457 into a non-jumbo instruction!
 
 这里写图片描述

PS1:将jar合并类成dex时,每一个方法都分配有一个id(合并类),当方法超过65535,就会遇到这个问题,解决方法就是在
    PS2:解决方法就是在在project.properties文件末尾处添加【dex.force.jumbo=true】,记得要clean/清理工程,并重新编译。

这里写图片描述

█ 相关资料:

● 1.2013-07-11【已解决】Eclipse的java代码出错:The import org.apache cannot be resolved – 在路上
 ● 2.2013-07-23 异常分析:Unable to execute dex: Cannot merge new index 71813 into a non-jumbo instruction! - super_spy的专栏 -CSDN博客
 ● 3.2014-06-23 Android-Cannot merge new index 66195 into a non-jumbo instruction的解决办法 - 若鱼的专栏 - CSDN博客

转载请注明出处:
http://blog.csdn.net/ljb568838953/article/details/80409666

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值