android - java.net.UnknownServiceException: CLEARTEXT communication to 10.0.2.2 not permitted by network security policy

 Bump into this error when trying to initate a service request to 


java.net.UnknownServiceException: CLEARTEXT communication to 10.0.2.2 not permitted by network security policy

2026-05-05 20:57:52.706  8867-8867  System.err              com.appcoreopc.getmyhome             W  at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:188)

2026-05-05 20:57:52.706  8867-8867  System.err              com.appcoreopc.getmyhome             W  at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)

2026-05-05 20:57:52.706  8867-8867  System.err              com.appcoreopc.getmyhome             W  at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)

2026-05-05 20:57:52.706  8867-8867  System.err              com.appcoreopc.getmyhome             W  at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)

2026-05-05 20:57:52.706  8867-8867  System.err              com.appcoreopc.getmyhome             W  at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)

To resolve it, we need to add 

app\src\main\res\xml\network_security_config.xml

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

And reference it in our android manifest.xml file 

    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        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/Theme.GetMyHome">
        <activity
            android:name=".SplashActivity"



Comments

Popular posts from this blog

vllm : Failed to infer device type

android studio kotlin source is null error

gemini cli getting file not defined error