Ionic 4: Failed facebook login with android 9.0, How to implement a solution?

I am working in an app using Ionic 4. One of the requeriments is the user can log in using facebook. I follow this tutorial: login facebook and works almost perfectly the functionality.

But testing the app I found out this: facebook login works good in all the android versions except with android 9.0

Always give me this error: “There is an error in logging you into this application. Please try again later”

enter image description here

Doing research I found the following issue:

“That’s happens because since Android Pie (9.0), you cannot make non secure http requests. Starting with Android 9 (API level 28), cleartext support is disabled by default.”

So I continued with the research and I find several solutions:

Ionic 4 app Login problem in Android Pie (9.0)

Ionic 4 Android 9.0 Login failed

Android 8: Cleartext HTTP traffic not permitted

As is commented in the previous answers, I tried to do the following

in config.xml file that is located in the root folder of the project i added:

android:usesCleartextTraffic="true"  // to allow clear text traffic

android:targetSandboxVersion="1"  // to recude level of securtiy


   <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
            <application android:networkSecurityConfig="@xml/network_security_config" android:targetSandboxVersion="1" android:usesCleartextTraffic="true" />
        </edit-config>
        <resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />

And did not work. Then I tried the second option. I searched in the project folder for this file: “network_security_config”

<resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />

So I can implement this solution:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">api.example.com(to be adjusted)</domain>
    </domain-config>
</network-security-config>

Here is my network_security_config.xml file code:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">https://www.facebook.com/</domain>
    </domain-config>
</network-security-config>

Obviously it didn’t work. I think the issue is, i dont now which url must be here:

<domain includeSubdomains="true">https://www.facebook.com/</domain> 

Any ideas how can overcome this? how to fix it?

The error is suggesting that you use only secure communication protocols (HTTPS). So I would suggest auditing every endpoint your app communicates with and ensure that it is an https:// one. In addition to presumably solving the problem you describe here, this approach helps protect your users.