How goes your app’s development? Are you receiving the error message “net::err_cleartext_not_permitted”? Well, good thing this article contains four great solutions to solve your Android Webview issue. We’ll cover what this error means and how you can solve the root problem. Continue reading below for some useful background information, causes of this error, and of course, the solutions.

What is Android Webview?
Android is an operating system with 87% of the global market share for mobile devices. As a result, Android applications can reach a much larger audience than applications designed for Apple. Additionally, it’s more difficult to be approved on Apple’s App Store than Google Play. For this reason, many application developers opt to focus on Android development.
Android WebView is a view used by developers to include functional web content into their applications. Android WebView isn’t a fascinating component, but it’s an integral Android development tool. Android WebView now updates independently of Android, and Google recommends all users update WebViews as updates become available. One downside to Webview is that any major outages or update issues will be experienced on any apps developed to use Webview. To prevent security issues, users should keep their Android operating system updated, as patches are no longer rolled out for Android version 4.3 and below.
On any Android phone, Webview is the only method to view content on the internet outside of a web browser. To contain all user actions within an application, a developer can implement Webview. For example, when a user clicks a link inside an application, the site will be loaded within the application instead of opening a pop-up web browser.
Cleartext is any information that has not been encrypted. As such, there is no need to decrypt the data to read it. Cleartext differs from plaintext, which is just plain language that might have been encrypted at some point. Information sent over the internet using cleartext can be subject to malicious attacks. The cleartext information may be stolen or manipulated.
To prevent tampering and other malicious activity, especially as cleartext data interacts with third-party servers, Google decided to disable cleartext information by default. Google implemented this change on Android 9 (API 28).
Note: Android 9 Pie was released on August 6th, 2018. Currently, the Android operating system is on version 11 (API 30).
Cleartext is typically sent over an HTTP (hypertext transfer protocol) URL. Following the Android 9 update, all applications using Android Webview should use HTTPS; otherwise, the system will throw the net::err_cleartext_not_permitted error. In short, this error will appear to users of your application because of Android’s network security configuration when accessing HTTP URLs.
How to solve the net::err_cleartext_not_permitted Android Webview error
Developers can solve the net::err_cleartext_not_permitted Android Webview error by allowing only HTTPS URLs in their application. Any website with a valid SSL certificate can be accessed using HTTPS. Therefore, you need to remove all unsecured URLs and force HTTPS for all websites.
Before proceeding to solutions to force HTTPS, you’ll learn a quick workaround. This option is available if you are unable to force all connections:
1. Edit AndroidManifest.xml
All Android applications will have an AndroidManifest.xml file. This file contains vital information about your application, such as activities and services. AndroidManifest.xml also provides permissions for protected parts of the application and declares the application’s Android API.
You are going to edit the application subelement (within manifest). You will be adding a simple application tag.
Warning: This workaround should only be a temporary fix, as it will compromise your user’s data integrity due to the major vulnerability posed by cleartext data over HTTP URLs.
Here is how to edit the AndroidManifes.xml:
- Find AndroidManifest.xml file in application folder at:
android/app/src/main/AndroidManifest.xml - Locate the application subelement.
- Add the following tag:
android:usesCleartextTraffic=”true” - The application subelement should now look like:
<application
android:name=”io.flutter.app.Test”
android:label=”bell_ui”
android:icon=”@mapmap/ic_launcher”
android:usesCleartextTraffic=”true”>
- Save the AndroidManifest.xml file.
The following two solutions will involve forcing HTTPS on either WordPress or HTML/PHP sites. If you are building an Android application to accompany a web application (there are many reasons to develop a native app), then you will anticipate much overlap in URLs. You can edit your website to force HTTPS usage as long as you have an SSL certificate installed.
2. Force HTTPS for WordPress Sites
To force HTTPS on a WordPress site, you will need to edit the .htaccess file. The .htaccess file is involved in managing redirects and permalinks.
- Login to your WordPress admin dashboard.
- Select Settings and then General from the left-hand dashboard.

- Locate WordPress Address (URL) and Site Address (URL) and make sure these URLs are HTTPS. Your site will need an SSL certificate for this.
- Now, you will need access to a file manager through FTP or cPanel to edit your WordPress files. There are alternative options, such as plugins that can also provide this functionality. Locate the .htaccess file within the root folder and Open the file.

- Within this file locate # BEGIN WordPress. This is the start of the WordPress rules that you are going to edit. Replace that entire section, ending with # END WordPress, with the following text. Be sure to replace the XXXX with your own domain name but do not rearrange the text in any other way:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ – [L]
# Rewrite HTTP to HTTPS
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://XXXX.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
- Make sure to save your changes to the .htaccess file.
3. Force HTTPS for HTML/PHP Sites
- Open FTP or cPanel and access the root directory for your site.
- If you are in cPanel you can click the + File button on the top toolbar. In FTP you can right-click inside the root directory and select Create new file. Create a file called .htaccess.
cPanel:

FTP:

- Now open the .htaccess file that was created in the root directory.
- If your site uses a www address then add the following block of code to your .htaccess file:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
- If your site uses a non-www address then add the following block of code to your .htaccess file:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^(www.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]
- If your site uses PHP you will also need to update your PHP Config file, site URL, and base URL variables.
4. Edit network_security_config.xml
This next solution is available for applications using Android version 7 or above. The network_security_config.xml file allows developers to edit the network security configuration to suit their application’s needs. You can edit this file to allow a specific domain name to bypass the security rules. Network traffic using this domain would not trigger the net::err_cleartext_not_permitted error.
To add a domain to the whitelist:
- Inside your Android application folder, add a file named network_security_config.xml at the following location:
res/xml/ - Add the following domain configuration text. Make sure to change the your_domain.com part to your website’s address.
<?xml version=”1.0″ encoding=”utf-8″?>
<network-security-config>
<domain-config cleartextTrafficPermitted=”true”>
<domain includeSubdomains=”true”>your_domain.com</domain>
</domain-config>
</network-security-config>
- Save the changes to the network_security_config.xml file.
- Find AndroidManifest.xml file in the application folder at:
android/app/src/main/AndroidManifest.xml - Locate the application subelement.
- Add the following text to specify the path to the network security configuration file:
<application
android:name=”.DemoApp”
android:networkSecurityConfig=”@xml/network_security_config”
net::err_cleartext_not_permitted Android Webview error solved
Android Webview is an excellent system component for any Android developer to have in their toolkit. Webview allows a developer to display web content, like your own or a third-party website, within the native application. If Webview is not used, the only method to display web content involves a disruption in the usage of the application. A browser, a completely different application, will open. Once a user leaves your application, they may never return. This can result in less traffic, ad revenue, and sales.
If you followed the solutions above, you would have edited your application’s AndroidManifest.xml file to add an exception for cleartext traffic. You have created and edited a network_security_config.xml file to whitelist a specific domain for cleartext network traffic.
If you are developing an application with significant URL overlap as a web application, then solutions 2 and 3 are especially useful. You learned how to force the use of HTTPS for either a WordPress or an HTML/PHP web application. It is done by editing the .htaccess file using cPanel or FTP.
If you would like to learn more about Android Network Security configuration and specifically cleartext traffic rules, you can do so here.
If you want to learn more about Android Webview, you can do so here. The documentation is excellent, and you will have a far better understanding of Android Webview if you read the documentation. As you learned above, there are some constraints associated with Webview.
You might also experience related Android WebView errors while building your app. However, there is no need to worry because we have covered the other common WebView error message, err_unknown_url_scheme, in a separate article.
After upgrading to Cordova Android 8.0, I am seeing net::ERR_CLEARTEXT_NOT_PERMITTED errors when trying to connect to http:// targets.
Why is that and how can I resolve this?
asked Feb 18, 2019 at 17:44
Oliver SalzburgOliver Salzburg
21.3k19 gold badges92 silver badges137 bronze badges
0
The default API level in the Cordova Android platform has been upgraded. On an Android 9 device, clear text communication is now disabled by default.
To allow clear text communication again, set the android:usesCleartextTraffic on your application tag to true:
<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:usesCleartextTraffic="true" />
</edit-config>
</platform>
As noted in the comments, if you have not defined the android XML namespace previously, you will receive an error: unbound prefix during build. This indicates that you need to add it to your widget tag in the same config.xml, like so:
<widget id="you-app-id" version="1.2.3"
xmlns="http://www.w3.org/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cdv="http://cordova.apache.org/ns/1.0">
answered Feb 18, 2019 at 17:44
Oliver SalzburgOliver Salzburg
21.3k19 gold badges92 silver badges137 bronze badges
11
There are two things to correct in config.xml
So the right answer should be adding the xmls:android:
<widget id="com.my.awesomeapp" version="1.0.0"
xmlns="http://www.w3.org/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cdv="http://cordova.apache.org/ns/1.0">
plus editing the config to allow:
<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:usesCleartextTraffic="true" />
</edit-config>
</platform>
If step 1 is avoided error: unbound prefix. will appear
answered May 22, 2019 at 18:07
zardiliorzardilior
2,66224 silver badges29 bronze badges
1
Cleartext here represents unencrypted information. Since Android 9, it is recommended that apps should call HTTPS APIs to make sure there is no eves dropping.
However, if we still need to call HTTP APIs, we can do following:
Platform: Ionic 4
Create a file named: network_security_config.xml under project-root/resources/android/xml
Add following lines:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain>ip-or-domain-name</domain>
</domain-config>
</network-security-config>
Now in project-root/config.xml, update following lines:
<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:usesCleartextTraffic="true" />
<application android:networkSecurityConfig="@xml/network_security_config" />
</edit-config>
... other statements...
It should work now.
answered Jul 19, 2019 at 9:01
AshutoshAshutosh
4,17910 gold badges56 silver badges100 bronze badges
5
To solve the problem there’s other option.
in file resources/android/xml/network_security_config.xml. insert:
<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">192.168.7.213:8733</domain>
</domain-config>
</network-security-config>
Im my case I´m using IP address then base-config is necessary, but if you have a domain. just add the domain.
answered Jun 7, 2019 at 12:12
Edvan SouzaEdvan Souza
1,0509 silver badges11 bronze badges
2
I ran into this problem myself today, and found a really nifty plugin that will save you the hassle of trying to manually allow cleartext traffic in Android 9+ for your Apache Cordova application. Simply install cordova-plugin-cleartext, and the plugin should take care of all the behind the scenes Android stuff for you.
$ cordova plugin add cordova-plugin-cleartext
$ cordova prepare
$ cordova run android
answered Nov 17, 2019 at 2:18
3
After a few days of struggle, this works for me, and I hope this also works for you.
add this to your CONFIG.XML, top of your code.
<access origin="*" />
<allow-navigation href="*" />
and this, under the platform 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:usesCleartextTraffic="true" />
<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" />
add the follow code to this file «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 includeSubdomains="true">YOUR DOMAIN HERE/IP</domain>
</domain-config>
</network-security-config>
answered Nov 16, 2019 at 15:50
SushilSushil
2,21526 silver badges25 bronze badges
6
Adding the following attribute within the opening < widget > tag worked for me. Simple and live reloads correctly on a Android 9 emulator. xmlns:android=»http://schemas.android.com/apk/res/android»
<widget id="com.my.awesomeapp" version="1.0.0"
xmlns="http://www.w3.org/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cdv="http://cordova.apache.org/ns/1.0">
answered Apr 21, 2019 at 21:49
Mark McCorkleMark McCorkle
9,3392 gold badges32 silver badges42 bronze badges
3
Im using IONIC 5.4.13, cordova 9.0.0 (cordova-lib@9.0.1)
I might be repeating information but for me problem started appearing after adding some plugin (not sure yet).
I tried all above combinations, but nothing worked.
It only started working after adding:
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
to file in project at
resources/android/xml/network_security_config.xml
so my network_security_config.xml file now looks like:
<?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 includeSubdomains="true">10.1.25.10</domain>
</domain-config>
</network-security-config>
Thanks to all.
answered Jan 22, 2020 at 9:36
RajendraRajendra
1,00914 silver badges20 bronze badges
9
After reading the whole discussion looking for a way to authorize communication to all IP addresses as in my case the IP address to where the request will be sent is defined by the user in an input text and can not be defined in the configuration file. Here is how I resolved the issue
here are the configuration
config.xml
<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" />
...
</platform>
resources/android/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
The most important piece of code is <base-config cleartextTrafficPermitted="true" /> in <network-security-config> instead of domain-config
answered Nov 11, 2020 at 10:02
stodistodi
1,46913 silver badges22 bronze badges
1
you should add
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
to
resources/android/xml/network_security_config.xml
like this
<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>
answered Aug 18, 2019 at 15:59
2
Just add this line to platforms/android/app/src/main/AndroidManifest.xml file
<application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" **android:usesCleartextTraffic="true"**>
answered Jul 19, 2020 at 6:49
Manoj AlwisManoj Alwis
1,24911 silver badges24 bronze badges
0
Following is the solution which worked for me. The files which I updated are as follows:
- config.xml (Full Path: /config.xml)
- network_security_config.xml (Full Path: /resources/android/xml/network_security_config.xml)
Changes in the corresponding files are as follows:
1. config.xml
I have added <application android:usesCleartextTraffic="true" /> tag within <edit-config> tag in the config.xml file
<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:usesCleartextTraffic="true" />
<application android:networkSecurityConfig="@xml/network_security_config" />
</edit-config>
...
<platform name="android">
2. network_security_config.xml
In this file I have added 2 <domain> tag within <domain-config> tag, the main domain and a sub domain as per my project requirement
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">mywebsite.in</domain>
<domain includeSubdomains="true">api.mywebsite.in</domain>
</domain-config>
</network-security-config>
Thanks @Ashutosh for the providing the help.
Hope it helps.
answered Nov 7, 2019 at 13:30
0
Following solution worked for me-
goto resources/android/xml/network_security_config.xml
Change it to-
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">localhost</domain>
<domain includeSubdomains="true">api.example.com(to be adjusted)</domain>
</domain-config>
</network-security-config>
answered Apr 1, 2020 at 8:33
LeenaLeena
6371 gold badge11 silver badges19 bronze badges
Old ionic cli (4.2) was causing issue in my case, update to 5 solve the problem
answered Jul 3, 2019 at 21:58
hugo blanchugo blanc
2813 silver badges13 bronze badges
1
I am running Ionic 5 with Vue and Capacitor 3 and was getting this error using the InAppBrowser for a website that doesn’t support https. For Capacitor apps, config.xml isn’t used and AndroidManifest.xml is edited directly.
First, create the Network Security Config file here YOUR_IONIC_APP_ROOTandroidappmainresxmlnetwork_security_config.xml.
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain>www.example.com</domain>
</domain-config>
</network-security-config>
Then edit YOUR_IONIC_APP_ROOTandroidappmainAndroidManifest.xml adding android:networkSecurityConfig="@xml/network_security_config" to application.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.ionic.starter">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!-- ... -->
</application>
<!-- ... -->
</manifest>
answered Apr 16, 2021 at 14:34
wsamohtwsamoht
1,5381 gold badge14 silver badges14 bronze badges
@Der Hochstapler thanks for the solution.
but in IONIC 4 some customization in project config.xml work for me
Add a line in Widget tag
<widget id="com.my.awesomeapp" version="1.0.0"
xmlns="http://www.w3.org/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cdv="http://cordova.apache.org/ns/1.0">
after this, in the Platform tag for android customize some lines check below
add usesCleartextTraffic=true after networkSecurityConfig and resource-file tags
<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" />
<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:usesCleartextTraffic="true" />
</edit-config>
</platform>
answered Jan 18, 2020 at 7:49
yashyash
2536 silver badges17 bronze badges
2
We are using the cordova-custom-config plugin to manage our Android configuration. In this case the solution was to add a new custom-preference to our config.xml:
<platform name="android">
<preference name="orientation" value="portrait" />
<!-- ... other settings ... -->
<!-- Allow http connections (by default Android only allows https) -->
<!-- See: https://stackoverflow.com/questions/54752716/ -->
<custom-preference
name="android-manifest/application/@android:usesCleartextTraffic"
value="true" />
</platform>
Does anybody know how to do this only for development builds? I would be happy for release builds to leave this setting false.
(I see the iOS configuration offers buildType="debug" for that, but I’m not sure if this applies to Android configuration.)
answered Dec 12, 2019 at 7:30
joeytwiddlejoeytwiddle
28.3k12 gold badges117 silver badges107 bronze badges
In an Ionic 4 capacitor project, when I packaged and deployed to android phone for testing I got this error. Resolved by re-installing capacitor and updating android platform.
npm run build --prod --release
npx cap copy
npm install --save @capacitor/core @capacitor/cli
npx cap init
npx cap update android
npx cap open android
answered Jan 22, 2020 at 20:48
If You have Legacy Cordova framework having issues with NPM and Cordova command. I would suggest the below option.
Create file android/res/xml/network_security_config.xml —
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">Your URL(ex: 127.0.0.1)</domain>
</domain-config>
</network-security-config>
AndroidManifest.xml —
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:networkSecurityConfig="@xml/network_security_config"
...>
...
</application>
</manifest>
answered Jan 22, 2020 at 22:16
PradeeptaPradeepta
2482 silver badges2 bronze badges
3
Android WebView is a system component powered by Chrome that allows Android apps to display web content. In other words, WebView is an embeddable browser that a native application can use to display web content.
One of the most common uses for a WebView is to display the contents of a link inside an app without leaving it. In recent Android versions, you might sometimes see ERR_CLEARTEXT_NOT_PERMITTED error if you try to open an unsecured URL (usually a HTTP URL).
Below is a screenshot of the error.

The very same unsecured URLs can be opened in Chrome, Edge or any dedicated browser just fine, which could cause confusion across new developers.
This article will explain why ERR_CLEARTEXT_NOT_PERMITTED happens, and what you can do to fix it.
Why does ERR_CLEARTEXT_NOT_PERMITTED happens?
Cleartext is any transmitted or stored information that is not encrypted or meant to be encrypted.
Anything that is transferred in unsecured URL can be categorized as cleartext information. Those information can be eavesdropped or tampered by a malicious third party. In rare cases, they can launch an attack directed towards your device or leaking your personal information.
Starting from Android 9.0 (API level 28), Google has decided to phase out support for cleartext network protocols in the WebView. Any attempt to access a non-HTTPS URL will raise ERR_CLEARTEXT_NOT_PERMITTED error.
The proper solution for this error is to simply use HTTPS URLs for all of your endpoints and remove all unsecured URLs from your codebase.
Workaround to avoid ERR_CLEARTEXT_NOT_PERMITTED
If you don’t have access to the infrastructure to force every connection to use HTTPS, you can try the adding the flag android:usesCleartextTraffic="true" into AndroidManifest.xml.
First you need to edit the Android Manifest file at android/app/src/main/AndroidManifest.xml and add the following line into the application tag.
Code language: JavaScript (javascript)
android:usesCleartextTraffic="true"
The file after the changes would look something like this :
BEFORE
Code language: HTML, XML (xml)
<application android:name="io.flutter.app.Test" android:label="bell_ui" android:icon="@mapmap/ic_launcher">
AFTER
Code language: HTML, XML (xml)
<application android:name="io.flutter.app.Test" android:label="bell_ui" android:icon="@mapmap/ic_launcher" android:usesCleartextTraffic="true">
The workaround might be good for testing and debugging. However, it leaves a big security hole and opens a threat to data integrity.
Android 7+ ERR_CLEARTEXT_NOT_PERMITTED solution
Another better solution introduced from Android 7.0 is to configure the network_security_config.xml file. You can read more about it in Google’s Network security configuration page.
Basically, network_security_config.xml allows you to whitelist a domain from the global security rules. Therefore, the traffic comes to and from that domain would not be raise ERR_CLEARTEXT_NOT_PERMITTED.
First, you need to create a file in res/xml/ and name it network_security_config.xml.
Then you need to add a domain configuration block and set cleartextTrafficPermitted flag to true so it would look like this.
<?xml version="1.0" encoding="utf-8"?> <network-security-config> <domain-config cleartextTrafficPermitted="true"> <domain includeSubdomains="true">your_domain.com</domain> </domain-config> </network-security-config>Code language: HTML, XML (xml)
After that, you need to spcify the path to your network security config file under your AndroidManifest so it would look like below :
Code language: HTML, XML (xml)
<application android:name=".DemoApp" android:networkSecurityConfig="@xml/network_security_config" ...
We hope that the solutions above help you solve your problem. Please note that the proper way to fix the error is using a secure network traffic protocol rather than a cleartext one.
We’ve also written a few other guides on fixing common Chrome error messages, such as How to fix ERR_SSL_PROTOCOL_ERROR and ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION that you may want to check out.
Opening URL inside any Android Application will use Android Webview and for some URLs, you might encounter ERR_CLEARTEXT_NOT_PERMITTED Error. The error should look similar to the below image.
So what this exactly mean?
Cleartext is any transmitted or stored information that is not encrypted or meant to be encrypted. When an app communicates with servers using a cleartext network traffic, such as HTTP, it could raise the risk of eavesdropping and tampering of content. Third parties can inject unauthorized data or leak information about the users. That is why developers are encouraged to secure traffic only, such as HTTPS. Starting with Android 9.0 (API level 28), cleartext support is disabled by default. Due to security purposes URL without HTTPS will throw err_cleartext_not_permitted error whenever an application uses it in the Android webview.
There’s an easy solution to fix err_cleartext_not_permitted error and i.e. don’t use insecure URLs. It is recommended to force HTTPs on your websites and remove all the insecure URLs i.e. non-HTTPs from the application. You will find the following guides helpful in forcing HTTPs on your websites.
Force HTTPS for WordPress websites by .htaccess
Force HTTPS on the HTML/PHP Websites using .htaccess
We hope the above guides help you to fix err_cleartext_not_permitted error for the insecure URLs.
Android Application Code Fix
If you are an application developer and facing the issue then this can be fixed by adding android:usesCleartextTraffic="true" flag in the AndroidManifest.xml file under the application block.
Open the android manifest file (android/app/src/main/AndroidManifest.xml) and add the following into the application tag.
android:usesCleartextTraffic="true"
Find an example below to add the flag correctly.
Before Code
<application
android:name="io.flutter.app.Test"
android:label="ginger_ui"
android:icon="@mipmap/ic_launcher">
After Code (changes/addition in bold)
<application
android:name="io.flutter.app.Test"
android:label="ginger_ui"
android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true">
Adding the above flag will start accepting the non-HTTPs Traffic in the app and fix err:ERR_CLEARTEXT_NOT_PERMITTED error. But still at the end of the day, better to use secure network traffic rather than cleartext.
Feel free to reach us out if you need kind of assistance with any technical queries. Shoot us an email at technical@basezap.com, and our professional experts will get in touch with you.
Learn how to prevent the net::ERR_CLEARTEXT_NOT_PERMITTED error from appearing in your Cordova application.
After 2 years of working with different technologies, I started using Cordova once again for a tiny side project. As usual with everything I work with, when trying something quite simple, there errors of any kind, this time the error seemed to be related to the network configuration.
Cause of this issue
This problem will always be triggered in your project if you haven’t enabled the cleartext support i nyour application. In my case with the Cordova In App Browser, the following code triggers the exception:
let ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
The apache website works normally in my browser, so what’s the real problem? In this case, when you trigger a request to http://apache.org, the server will make a redirect because the https connection is missing as well as the www that is forced when you create the request. Your application blocks the first redirect as it has been done through HTTP (insecure). If you trigger the request using https, then it works perfectly:
let ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'location=yes');
Thats the reason of this problem. Clear Text traffic is basically text that has not been subjected to encryption and is not meant to be encrypted.
Possible solution #1
The most obvious solution is to simply add the correct protocol to the website that you’re trying to open (HTTPS) as long as the server from which the information is requested supports said protocol.
Possible solution #2
The first solution isn’t that useful when you are working with websites that don’t offer a secure connection or with local files.
As mentioned, the cleartext traffic support is disabled by default Starting with Android 9 (API level 28), so you can enable it if you need to. Simply add the following attribute to the application node in your AndroidManifest.xml file:
android:usesCleartextTraffic="true"
Your file will look like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourcompany.packagename">
<application
...
android:usesCleartextTraffic="true"
...
>
This will allow the clear text traffic from any source which depending on your needs may be the best solution. Try building your application and launch the In App Browser with the URL that was throwing the exception and it should work now.
Possible solution #3
Alternatively if you need to allow the clear text traffic from certain sources only, you may specify it using the network security configuration file of your android application (res/xml/network_security_config.xml):
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config>
<domain
includeSubdomains="true"
cleartextTrafficPermitted="true"
>example.com</domain>
</domain-config>
<base-config cleartextTrafficPermitted="false"/>
</network-security-config>
Change the example.com domain with the one you need and be sure to use the mentioned configuration file in your AndroidManifest.xml file like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourcompany.packagename">
<application
android:networkSecurityConfig="@xml/network_security_config"
>
Happy coding ❤️!
29. January 2021
Ionic
Comments (0)
Started first ionic app with angular, and when I execute it with command
> ionic capacitor run android —l —external
[Note: Make sure to execute the command under your project directory]
It compiled successfully in VS Code and Android. Only in Virtual Device it was showing Error:
The webpage could not be loaded because:
net::ERR_CLEARTEXT_NOT_PERMITTED
Error Info: Cleartext is any transmitted or stored information that is not encrypted or meant to be encrypted. When an app communicates with the server using a cleartext network traffic,
such as HTTP, it could raise the risk of eavesdropping and tampering of content.
Solution: Go to capacitor.config.json file and add «cleartext»:true, rebuild the application and execute it once again. your app should be working now.
{
"appId": "io.ionic.starter" ,
"appName": "kgkjgkjgk",
"bundledWebRuntime": false,
"npmClient": "npm",
"webDir": "www",
"plugins": {
"SplashScreen": {
"launchShowDuration": 0
}
},
"cordova": {},
"server": {
"cleartext": true,
"url": "http://172.16.13.205:8100"
}
}
This option in capacitor.config.json file will add android: usesCleartextTraffic=»true» under provider tag in AndroidManifest.xml file(android>app>src>mail>AndroidManifest.xml). You can add this option in the Manifest file manually but giving this task to the capacitor is easier.
<provider
android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false"
android:grantUriPermissions="true"
android:usesCleartextTraffic="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data> </provider>
</application>
Hope this is helpful, Thank you.
Solution Reference : https://stackoverflow.com/questions/60906953/ionic-5-capacitor-err cleartext-not-permitted-in-android
For Detail understanding about the error: http://www.androidtutorialshub.com/cleartext http-traffic-not-permitted/
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Closed
diachedelic opened this issue
Aug 7, 2020
· 13 comments
Comments
I just ran into this. I didn’t want to allow http for the entire app, so here is my fix if it helps others:
- Create android/app/src/main/res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?> <network-security-config> <domain-config cleartextTrafficPermitted="true"> <domain includeSubdomains="true">localhost</domain> </domain-config> </network-security-config>
- specify the network security config in android/app/src/main/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.worldspinner.portraits"> <application . . . android:networkSecurityConfig="@xml/network_security_config"> . . . </application> . . . </manifest>
This issue has possibly reoccurred on at least one device — all I see in the log is «TypeError: Failed to fetch» so it may be a different issue.
Chrome Mobile WebView 66.0.3359
Pixel 3 XL
Android 9
I was able to reproduce the net::ERR_CLEARTEXT_NOT_PERMITTED issue when using Capacitor’s live reload feature.
With live reload an ionic serve runs on the development machine and is exposed to the mobile device over a local WiFi network using a dynamic, local IP address. That local IP is used to serve the front-end app in the WebView. Since it’s an IP address and not localhost it doesn’t work as expected.
What happens in the app is the splash screen doesn’t hide. If I background the app and then bring it back into the foreground, the splash screen hides and you can see the error message.
If you add a <domain> to the config for the IP address in addition to localhost, then it works as expected. That’s a manual step though that’s likely cause for confusion and lost time during the development workflow.
It appears that Capacitor live reload automatically adds android:usesCleartextTraffic="true" to the application element of android/capacitor-cordova-android-plugins/src/main/AndroidManifest.xml so that the WebView traffic itself is permitted using an IP address. It would seem that this is being trounced by the manual configuration recommended by capacitor-blob-writer in network_security_config. See https://developer.android.com/guide/topics/manifest/application-element where it discusses android:usesCleartextTraffic: «This flag is ignored on Android 7.0 (API level 24) and above if an Android Network Security Config is present.»
For us live reload working well on Android is important not only for the shortened feedback loop for front-end changes but also because that’s our workaround for getting TypeScript source maps working with the Chrome dev tools during remote WebView debugging.
@KevinKelchen Do you see then net::ERR_CLEARTEXT_NOT_PERMITTED error in response to a BlobWriter call, or somewhere else?
Is there a way to further configure the network_security_config such that it behaves like android:usesCleartextTraffic="true"?
Thank you for responding! 😀
@KevinKelchen Do you see then net::ERR_CLEARTEXT_NOT_PERMITTED error in response to a BlobWriter call, or somewhere else?
When I described the net::ERR_CLEARTEXT_NOT_PERMITTED occurring and talked about the splash screen not hiding and such, that was upon application launch and BlobWriter is not being used at that point. What’s messed up is the WebView’s ability to load data from the ionic serve running on the development machine at an IP address such as http://192.168.0.104:8100.
As mentioned above, this is because the presence of a android:networkSecurityConfig overrides Ionic’s dynamic addition of android:usesCleartextTraffic that they add for facilitating live reload from an external IP address. The android:networkSecurityConfig only allows clear text over the localhost domain. That continues to work fine for the WebView when not using live reload or in production when the front-end app is served at a hostname of localhost, but during live reload it’s an IP address that can potentially change often. The android:networkSecurityConfig‘s specification of a domain like localhost makes it act like an allow list and therefore blocks any http traffic not explicitly in android:networkSecurityConfig such as the IP address.
Is there a way to further configure the network_security_config such that it behaves like android:usesCleartextTraffic=»true»?
I think you might be able to with <base-config cleartextTrafficPermitted=»true»>. However, we wouldn’t want that in a production/release build while we would want the localhost configuration for BlobWriter always. Since BlobWriter may have to be configured using android:networkSecurityConfig and we always want it to work, and since that overrides android:usesCleartextTraffic, then perhaps one workaround could be to have separate android:networkSecurityConfig files for debug and release builds. The debug build would allow anything and the release build would only allow localhost. A downside is that in debug mode while developing there could be a clear text-related issue you wouldn’t catch until the app is built in release mode and you try it out. Probably not very common to happen but still something to note.
It’d be more preferable if it was tied to just a live reload scenario like if the Ionic CLI could add the IP to the existing android:networkSecurityConfig if one exists as a temporary change while the live reload is in progress similar to how it temporary modifies other files during live reload to add android:usesCleartextTraffic and such.
I like the last suggestion, as it is possible the user has configured a network_security_config for other purposes than BlobWriter.
What’s messed up is the WebView’s ability to load data from the ionic serve running on the development machine
That’s odd, because I use HMR all the time, though not via the Ionic CLI command. Perhaps this is different to Live Reload? I just set server.url in capacitor.config.js to my IP address and away I go. (I do however run a patched version of Capacitor which lets me access the filesystem via URLs, see ionic-team/capacitor#3433.)
Thank you for the crazy-fast reply! 😀
That’s odd, because I use HMR all the time, though not via the Ionic CLI command. Perhaps this is different to Live Reload? I just set server.url in capacitor.config.js to my IP address and away I go. (I do however run a patched version of Capacitor which lets me access the filesystem via URLs, see ionic-team/capacitor#3433.)
Interesting. I would think if the Android WebView’s server.url is an IP address with the android:networkSecurityConfig configured as mentioned in the README that your IP address over http would be blocked because it’s clear text. 🤔 I’m not sure if the Capacitor patch would affect that or not.
Yes, I don’t think the patch would affect that. However, I did just test plain old server.url on my Android running Chrome v88, and the app loaded OK.
Perhaps Ionic Live Reload uses XHR to transfer the file or something? I do not set usesCleartextTraffic in my AndroidManifest.xml.
Thanks for the reply and for trying that out and sharing the information!
Huh—interesting. If you haven’t checked, I suppose it’s possible that the final/built version of the AndroidManifest.xml could have somehow gotten android:usesCleartextTraffic added to it. To check, open the app’s AndroidManifest.xml and then click the Merged Manifest button/tab.
It’s also possible that your front-end dev server/tooling is configured differently somehow. I’m using the Ionic CLI which calls into the Angular CLI, FWIW.
Hmm no sign of `usesCleartextTraffic` in the merged manifest. I use Vue CLI for my HMR. I can only assume Ionic CLI is doing some proxying and it’s going wrong there?
…
On 4 Feb 2021, at 12:06 pm, Kevin Kelchen ***@***.***> wrote:
Thanks for the reply and for trying that out and sharing the information!
Huh—interesting. If you haven’t checked, I suppose it’s possible that the final/built version of the AndroidManifest.xml could have somehow gotten android:usesCleartextTraffic added to it. To check, open the app’s AndroidManifest.xml and then click the Merged Manifest button/tab.
It’s also possible that your front-end dev server/tooling is configured differently somehow. I’m using the Ionic CLI which calls into the Angular CLI, FWIW.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub <#20 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AACLZQE6VZXKMGO5TN6LCGLS5IBZVANCNFSM4PXH7EUQ>.
I just ran into Kevin’s issue. I have no idea why it only started happening now. It does appear that BlobWriter’s network security config breaks Capacitor’s live reload (as the network address of the web server is not listed as a <domain>).
diachedelic
pushed a commit
that referenced
this issue
Feb 24, 2022
Specifying only 'localhost' in a network security config will break the
webview when the app is loaded over the local network via HTTP. A
simple, if rather brutish, alternative is to allow cleartext on all
domains.
close #20
Glad at least that I’m not the only one who bumped into this issue, @diachedelic! 😅
Do you think there might security concerns by allowing cleartext traffic to all domains?
FWIW, due to potential security concerns, I will describe the workaround we used in our app. It’s basically what I described above:
I think you might be able to with <base-config cleartextTrafficPermitted=»true»>. However, we wouldn’t want that in a production/release build while we would want the
localhostconfiguration for BlobWriter always. Since BlobWriter may have to be configured usingandroid:networkSecurityConfigand we always want it to work, and since that overridesandroid:usesCleartextTraffic, then perhaps one workaround could be to have separateandroid:networkSecurityConfigfiles for debug and release builds. The debug build would allow anything and the release build would only allowlocalhost. A downside is that in debug mode while developing there could be a clear text-related issue you wouldn’t catch until the app is built in release mode and you try it out. Probably not very common to happen but still something to note.
It’s hard to believe it’s been over a year since that comment, but so far we’ve had no issues with our workaround.
Workaround
- In
/android/app/src/main/AndroidManifest.xml,- On the
manifest -> applicationelement, add the attribute:android:networkSecurityConfig="${networkSecurityConfigPath}"
- On the
- In
/android/app/build.gradle,- In the
android.defaultConfigobject, add the property:manifestPlaceholders = [networkSecurityConfigPath:"@xml/debug_network_security_config"]
- In the
android.buildTypes.releaseobject, add the property:manifestPlaceholders = [networkSecurityConfigPath:"@xml/network_security_config"]
- In the
- In the
/android/app/src/main/res/xmlfolder, create a file named:debug_network_security_config.xml
- In
/android/app/src/main/res/xml/debug_network_security_config.xml, populate the file with the following:-
<?xml version="1.0" encoding="utf-8"?> <network-security-config> <!-- Used to allow the WebView to load non-https traffic in debug mode. Needed when using Capacitor Live Reload or when the `localhost` hostname is not used for the WebView. The reason this is needed is that the cleartext configuration required for `capacitor-blob-writer`'s `localhost` server (see `network_security_config.xml`) will make it so *only* `localhost` is allowed to make non-https requests. While that's fine for the WebView in production as it uses `localhost`, in debug where a dynamic hostname that's not `localhost` can be used, the WebView would not be able to load the front-end app files. So in debug mode we're going to allow *any* non-https traffic and in release mode we'll only allow non-https traffic to `localhost`. See https://github.com/diachedelic/capacitor-blob-writer/issues/20#issuecomment-772831304 to learn more. --> <base-config cleartextTrafficPermitted="true"></base-config> </network-security-config>
-
- In the
/android/app/src/main/res/xmlfolder, create a file named:network_security_config.xml
- In
/android/app/src/main/res/xml/network_security_config.xml, populate the file with the following:-
<?xml version="1.0" encoding="utf-8"?> <network-security-config> <!-- Used to allow the WebView to load non-https traffic in release mode. Needed for `capacitor-blob-writer`'s `localhost` server so the app is allowed to make non-https requests to it. By opting into this we also have to make sure that the WebView's `hostname` also allows cleartext. See `debug_network_security_config.xml` for additional information. --> <domain-config cleartextTrafficPermitted="true"> <domain includeSubdomains="false">localhost</domain> </domain-config> </network-security-config>
-
Final thoughts
If this workaround doesn’t become the official recommended configuration, that’s probably ok. I at least wanted to provide the workaround as an option for anyone who might be leery of allowing cleartext traffic to all domains. 🙂
Thanks for all that you do to maintain this awesome and much-needed plugin, @diachedelic! 😀





