Error text
java.net.UnknownServiceException: CLEARTEXT communication to api.example.com not permitted by network security policy
java.net.UnknownServiceException: CLEARTEXT communication to api.example.com not permitted by network security policy
From Android 9 up, http:// requests are blocked by default. The app is trying to reach an unencrypted address.
https:// and change the address.network_security_config.xml and allow the specific domain (10.0.2.2, localhost).<application android:networkSecurityConfig=...>.usesCleartextTraffic="true" for all traffic; keep it in the debug build only.<!-- res/xml/network_security_config.xml -->
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
</domain-config>
</network-security-config>
<application android:networkSecurityConfig="@xml/network_security_config" ...>Use HTTPS only in release and keep the http allowance in the debug source set.
Author and license: Nibras Code