Caching on Android 9

Network Security Config

In the Audience Network Android SDK, we use (localhost) as a caching proxy to cache media files in the SDK. Since Android 9, cleartext traffic (unencrypted HTTP) will be blocked by default, which will affect the functionality of media caching of the SDK and could affect user experience and ads revenue.

In order to mitigate that, you can add allow list clear text traffic to the address of which is the local address of the device itself.

You can do this using the Android network security configuration.

In case you are already using custom network security configuration to opt out from cleartext traffic, make sure to add as a permitted domain.

Add a Network Security Configuration File

The Network Security Configuration feature uses an XML file where you specify the settings for your app. If you haven't done so, under the xml folder of the app resources, you can create a new XML file: res/xml/network_security_config.xml.

Then in your application manifest AndroidManifest.xml, add the configuration to your application attribute as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application android:networkSecurityConfig="@xml/network_security_config"
... >

Adding localhost to Permitted Cleartext Traffic Domain

In the res/xml/network_security_config.xml file, you can add localhost to the permitted cleartext traffic domain by adding:

<?xml version="1.0" encoding="utf-8"?>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true"></domain>

After you have done this, the caching in the Audience Network SDK should function correctly.