How can I enable cleartext traffic (plain http:// URLs) on Android?

Symptoms

  • During the build, the following warning is logged to the console:

    The application's Target API Level is set to 28 or higher, which means that Android will block requests to plain http:// (non-https) URLs by default.

  • When the application tries to load a plain http:// URL at runtime, the webview displays a net::ERR_CLEARTEXT_NOT_PERMITTED error message.

Cause

Starting in Android 9.0 (API Level 28), Android now blocks applications from loading plain http:// URLs by default because traffic over those requests is unencrypted.

Resolution

If your application must support loading plain http:// URLs, you can opt into enabling cleartext traffic by using an AndroidManifest.xml file that includes an android:usesCleartextTraffic="true" application attribute. You can do that with the following steps.

  1. Download this example AndroidManifest.xml file that includes the needed android:usesCleartextTraffic="true" attribute.

  2. Place the file in your project at Assets/Plugins/Android/AndroidManifest.xml. This location must be exact or else Unity will not detect its presence.

  3. Rebuild your application.

For more information, see this Stack Overflow answer.