ClassNotFoundException: Didn‘t find class “org.apache.http.message.BasicNameValuePair“解决方法

在Androdid高版本中删除了httpclient相关的包
可通过在as中配置依赖解决:

首先需要在AndroidManifest.xml文件的application标签里面加入

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

然后添加该权限:

<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>

在入口文件BaseApplication重写

 @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
//        if (base != null) {
//            throw new IllegalStateException("Base context already set");
//        }
        context = BaseApplication.this;
    }

在app的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'
}

参考转载
 

ClassNotFoundException: Didn't find class "org.apache.http.message.BasicNameValuePair"解决方法_classnotfoundexception: org.apache.thrift.protocol-优快云博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值