Reputation: 301
I am using Laravel Echo Ionic on the project. I get ERR_CLEARTEXT_NOT_PERMITTED error while running it on mobile devices but it is running fine on webview and emulator.
I have tried to add
<uses-permission android:name=“android.permission.INTERNET” />
<uses-permission android:name=“android.permission.ACCESS_NETWORK_STATE” />
<uses-permission android:name=“android.permission.ACCESS_WIFI_STATE” />
on AndroidManifest.xml
but, it doesn't work.
and i've tried to add
<access origin=“*”/>
<allow-intent href=“*” />
<allow-navigation href=“*” />
on config.xml.
and lastly i've tried to modify config.xml with
<edit-config file=“app/src/main/AndroidManifest.xml” mode=“merge” target=“/manifest/application”>
<application android:usesCleartextTraffic=“true” />
</edit-config>
but all doesn't work for me.
Any idea how to fix this problem?
Upvotes: 4
Views: 8309
Reputation: 21
To run it on mobile devices you need to make some configurations in your project, following the file path below you will arrive at three possible solutions
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>localhost</domain>
<domain includeSubdomains="true">YOUR DOMAIN/IP</domain>
</domain-config>
</network-security-config>
config.xml
<access origin="*" />
<platform name="android">
<preference name="Scheme" value="http" />
<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" />
<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" />
</platform>
platforms/android/app/src/main/AndroidManifest.xml
<application android:usesCleartextTraffic="true">
Upvotes: 1
Reputation: 2973
network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">localhost</domain>
<domain includeSubdomains="true">173.249.51.122</domain>
</domain-config>
</network-security-config>
Enter Only IP address (No http:// or https://). It's work for me
Upvotes: 2
Reputation: 23
My network_security_config.xml file some changes in it you can try. This is worked for me. Add your IP address
<?xml version="1.0" encoding="utf-8"?><network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain>localhost</domain>
<domain>http://192.168.0.51:8082/hbpms"</domain>
</domain-config>
Upvotes: -2
Reputation: 500
It just happened to me recently and if you are trying to connect from your device to any external server (since you mention about laravel echo, then I assume that you are trying to connect to an IP), then maybe you can try this.
If you notice, the network_security_config.xml located in "resources" folder will be copied into your android "app" folder
...
<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>
<resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
<allow-intent href="market:*" />
<icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
<icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
<icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
...
</platform>
...
Maybe try to modify network_security_config.xml file located in resources/android/xml/network_security_config.xml into :
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain>localhost</domain>
<domain>your_external_ip_here</domain>
</domain-config>
</network-security-config>
Hope this help.
Upvotes: 12