(安卓异常)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://
客户端所有网址对应修改。

 

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