0

I am working on how to connect my app to a server which is running on NodeJS and MongoDB, I am relatively a beginner so I wondered how do i connect them, I am currently using Retrofit for making a connection as many suggested I have created a network security config xml file I have tried it then i have seen this article in android website suggesting it is discontinued after android 8.1 text

I am getting an error of CLEARTEXT communication to localhost (I also tried with 10.0.2.2) is not permitted by network security policy. I have also checked the YouTube for any recommends but nobody has worked on it yet... Can anybody suggest/write the answer

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="false">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">10.0.2.2</domain> <!-- If using emulator -->

        <!-- Add other domains as needed -->
    </domain-config>
</network-security-config>

as well as in AndroidManifest.xml

android:usesCleartextTraffic="true"

I have added it too

enter image description here

1 Answer 1

1

The flag android:usesClearTextTraffic is ignored below SDK Level 23, i.e Android 6, marshmallow, as you rightly said

What you have done wrong here, is adding both the things together

If you set this flag, it should work above API 23, without any issues for you

android:usesCleartextTraffic="true"

But you also have an additional network security config, where you explicitly say that you don't want to permit clear text traffic

 <domain-config cleartextTrafficPermitted="false"> // This should be true, to allow request to HTTP servers like localhost

So there is a conflict, one place is true, one place is false. Both should ideally be the same

Not the answer you're looking for? Browse other questions tagged or ask your own question.