How to Solve Cleartext HTTP traffic not permitted Error in Android Studio

ERROR:

08-29 12:03:11.246 11285-11285/ E/: [12:03:11.245, main]: Exception: IOException java.io.IOException: Cleartext HTTP traffic to * not permitted
at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:115)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:458)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
at com.deiw.android.generic.tasks.AbstractHttpAsyncTask.doConnection(AbstractHttpAsyncTask.java:207)
at com.deiw.android.generic.tasks.AbstractHttpAsyncTask.extendedDoInBackground(AbstractHttpAsyncTask.java:102)
at com.deiw.android.generic.tasks.AbstractAsyncTask.doInBackground(AbstractAsyncTask.java:88)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)

Solution:

According to Network security configuration -

Starting with Android 9 (API level 28), cleartext support is disabled by default.

Also have a look at Android M and the war on cleartext traffic

Codelabs explanation from Google

Option 1 -

First try hitting the URL with “https://” instead of “http://”

Option 2 -

Create file res/xml/network_security_config.xml -

<?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>
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:networkSecurityConfig="@xml/network_security_config"
...>
...
</application>
</manifest>

Also android:targetSandboxVersion can be a problem as well.

  • The target sandbox that this app should use. if the sandbox version number is higher then the security level must be higher. The default value is 1. You can also set it to 2. If you set this attribute to 2, the application switches to another SELinux sandbox. At level 2 sandbox the following restrictions applying.
  • The default value for usesCleartextTraffic in the network security configuration is false.
  • UID sharing is not allowed.

That’s ass, we will learn how to Solve Cleartext HTTP traffic not permitted Error in Android Studio.

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Attach a debugger to an app with Android Studio for app event trackingy

Wild Storage | Part 1 — Performance for queries

10 ideas to improve your Gradle build times [Part I]

Getting started with Jetpack Compose

Coroutines in Kotlin

Nekopoi Care Apk Download Terbaru, Nonton Film Anime Gratis

Nekopoi Care Apk Download Terbaru, Nonton Film Anime Gratis

Hardcoded credential leaks — API Key in Android apps

Creating Widgets with Custom Builder Functions in Flutter

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
LearnWithSathya

LearnWithSathya

More from Medium

Understanding Bidirectional Dijkstra’s Algorithm

I’m continuing my learning of the Binary Search Trees, so this post contains notes that I took on…

How To Manually Update Android Version

leetcode 1152. Analyze User Website Visit Pattern