org.apache.http.legacy 不适用于 API 28 [英] org.apache.http.legacy doesn't work on API 28
问题描述
首先,我使用 org.apache.http 函数有一段时间了,当我尝试在 API 28 上启动我的应用程序时出现错误.它正在 API 26 和 API 23 上运行,但突然 API 出现问题28. 谷歌做了一些改变吗?
To begin with, I was using org.apache.http functions for a while now and error came when I tried to launch my app on API 28. It's working on API 26 and API 23, but suddenly something is wrong with API 28. Did Google made some changes?
推荐答案
要在 Android 9.0 Pie 中完美运行 org.apache.http.legacy 创建一个 xml 文件 res/xml/network_security_config.xml
To run org.apache.http.legacy perfectely in Android 9.0 Pie create an xml file res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
并在您的 AndroidManifest.xml 中添加 2 个标签
And add 2 tags tag in your AndroidManifest.xml
android:networkSecurityConfig="@xml/network_security_config"android:name="org.apache.http.legacy"
android:networkSecurityConfig="@xml/network_security_config" android:name="org.apache.http.legacy"
<?xml version="1.0" encoding="utf-8"?>
<manifest......>
<application android:networkSecurityConfig="@xml/network_security_config">
<activity..../>
......
......
<uses-library
android:name="org.apache.http.legacy"
android:required="false"/>
</application>
还要在您的应用构建 gradle 中添加 useLibrary 'org.apache.http.legacy'
Also add useLibrary 'org.apache.http.legacy'
in your app build gradle
android {
compileSdkVersion 28
defaultConfig {
applicationId "your application id"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
useLibrary 'org.apache.http.legacy'
}
这篇关于org.apache.http.legacy 不适用于 API 28的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!