ClassNotFoundException: Didn’t find class “org.apache.http.message.BasicNameValuePair“

导入应用出现报错:
ClassNotFoundException: Didn’t find class "org.apache.http.message.BasicNameValuePair"

平台说明:
RK3368-9.0
背景说明:
洒家需要导入带联网功能的应用,像获取天气,或者获取版本之类的应用
错误现象说明:
概率性出现报错,有时候直接导入系统可以,重新编译又出现问题,有时候就都没有问题
原因:
httpclient相关包被删除
尝试方法:
方法1 :配置build.gradle

apply plugin: ‘com.android.application’
android {
		compileSdkVersion 28
		defaultConfig {
...
...
    lintOptions {
        abortOnError false
    }
    // 1.加入这句话
    useLibrary 'org.apache.http.legacy'
}
...

// 2.加入以下这些
packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
}
在依赖中加上
dependencies {
		//3.加入以下这些
		//noinspection DuplicatePlatformClasses
		api 'org.apache.httpcomponents:httpclient:4.4.1'
}

结果:无效,问题还在

方法2:
在app manifest里添加

<application>
	<uses-library
		android:name="org.apache.http.legacy"
		android:required="false" />
<application>

结果:无效,问题还在

方法3:在前两种方法的基础上,添加network_security_config.xml

1 在前两种方法的基础上,在res下新建xml文件夹放入network_security_config.xml
2指定android:networkSecurityConfig="@xml/network_security_config"
<application
    	android:allowBackup="true"
    	android:name=".taibao"
    	android:icon="@drawable/ic_launcher"
    	android:supportsRtl="false"
    	android:networkSecurityConfig="@xml/network_security_config"
    	android:label="@string/app_name">
3 network_security_config.xml内容如下
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>    	
   
结果:成功
原因:找不到Lorg/apache/http/message/BasicNameValuePair
改为不依赖系统的apache库,改为应用内单独依赖

总结:

RK方案概率性出现NoClassDefFoundError,可以尝试以上三种方法,洒家认为总有一款适合你~
其他方案类似问题也可以类比验证问题是否解决。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值