android 开发中java.net.UnknownServiceException: CLEARTEXT communication to ...错误解决方案

android 开发报错:

报错信息:java.net.UnknownServiceException: CLEARTEXT communication to 192.168.43.232 not permitted by   network security policy

W/System.err: java.net.UnknownServiceException: CLEARTEXT communication to 192.168.43.232 not permitted by network security policy
        at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:146)
        at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)

解决方案:

(1)在res目录下创建一个xml文件夹,并创建文件network_security_config.xml,内容如下: 



    

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

android:networkSecurityConfig="@xml/network_security_config"

(3)完整如下:

    
        
            
                

                
            
        
    

 

转自:

https://blog.csdn.net/qq_40833790/article/details/101604707

表示感谢!!

你可能感兴趣的:(android)