在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'
}
参考转载