Http兼容API28->java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion

安卓在9.0的時候限制了Http,所以運行的時候就會報上面的錯誤,爲了兼容HttpClient只需要兩步:

只要最大SDK>=28,想要使用Http必須配置如下兩項

1.在Application節點添加 

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

2.在Application節點添加android:networkSecurityConfig="@xml/network_security_config"

 2.1 在res文件夾下新建xml文件夾,在裏面新建一個xml文件,文件內容如下:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章