System.err: java.net.UnknownServiceException: CLEARTEXT communication to 192.168.43.172 not permitte

解决方式
在res目录下创建一个xml文件夹,并创建文件network_security_config.xml,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config xmlns:android="http://schemas.android.com/apk/res/android">
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

然后在AndroidManifest.xmlapplication结点中引用此xml文件

android:networkSecurityConfig="@xml/network_security_config"

完整如下:

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:networkSecurityConfig="@xml/network_security_config"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

你可能感兴趣的:(Bug)