0

I know that a similar question was raised under Why am I seeing net::ERR_CLEARTEXT_NOT_PERMITTED errors after upgrading to Cordova Android 8? but unfortunately non of the answers fixed my problem.

enter image description here

  • Ionic Framework : @ionic/angular 5.8.4
  • @angular-devkit/build-angular : 0.901.13
  • Cordova CLI : 10.0.0 (cordova-lib@10.1.0)
  • Cordova Platforms : android 9.0.0, browser 6.0.0
  • Android Studio 2020.3.1

After deleting the platforms folder of my ionic project, I wanted to emulate my project again by running:

sudo ./Android/Sdk/emulator/emulator -avd Pixel_3a_API_28

cordova prepare android

ionic cordova emulate android -l

And all of a sudden I always get the error message that there is a network problem. That has never happened before to me, so I tried to add the configs from the link above. Here is my resources/android/xml/network_security_config.xml:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system"/>
        </trust-anchors>
    </base-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
    </domain-config>
</network-security-config>

and part of my config.xml (and I tried all versions from the link above!):

    <platform name="android">
        <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" />
        </edit-config>
        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
            <application 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" />

I installed new virtual device using Android Studio, but same error.

nogamawa
  • 145
  • 6
  • 15
  • Use IP instead of localhost At capacitor.config.json add I as "server": { "url": "http://192.168.xxx", "cleartext": true, "allowNavigation": [ "localhost", "http://192.168.xxx" ] } – Stefani Toto Oct 26 '21 at 11:42

1 Answers1

0

Check your config.xml file and ensure this content source is set like this:

<content src="index.html" />

Anything else should be removed and revert back to the above.

mahen23
  • 720
  • 2
  • 11
  • 24