(安卓異常)CLEARTEXT communication to host not permitted by network


CLEARTEXT異常修復:

CLEARTEXT communication to host not permitted by network


方案一:

1、修改AndroidManifest.xml:    application中添加屬性 android:networkSecurityConfig="@xml/network_security_config"

2、添加文件至路徑:        res/xml/network_security_config.xml

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


示例:

<application
        android:name=".App"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"

        android:networkSecurityConfig="@xml/network_security_config"

        android:roundIcon="@mipmap/ic_launcher_round"
        android:theme="@style/AppTheme">
</application>

方案二:

targetSdkVersion設置爲小於28

<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="27" />


方案三:

服務器網址由http://升級爲https://
客戶端所有網址對應修改。

 

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